From 130f82405be22bab13a6c429cabf72d0e73da08a Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Tue, 1 Oct 2024 18:57:20 +0000 Subject: [PATCH] CodeGen from PR 30796 in Azure/azure-rest-api-specs Merge 35cfe08c583c3ef0dbe433c53f4eef038b1fb556 into 6d9e0951ddb28d567d54e4316bba6fa19626be43 --- .../_meta.json | 10 +- .../cosmosdbforpostgresql/_configuration.py | 7 +- .../_cosmosdb_for_postgresql_mgmt_client.py | 29 +- .../cosmosdbforpostgresql/_serialization.py | 94 ++- .../mgmt/cosmosdbforpostgresql/_version.py | 2 +- .../aio/_configuration.py | 7 +- .../_cosmosdb_for_postgresql_mgmt_client.py | 31 +- .../aio/operations/_clusters_operations.py | 581 +++++++----------- .../operations/_configurations_operations.py | 298 +++------ .../operations/_firewall_rules_operations.py | 198 +++--- .../aio/operations/_operations.py | 37 +- ...private_endpoint_connections_operations.py | 199 +++--- .../_private_link_resources_operations.py | 60 +- .../aio/operations/_roles_operations.py | 198 +++--- .../aio/operations/_servers_operations.py | 60 +- .../cosmosdbforpostgresql/models/__init__.py | 14 + ...smosdb_for_postgresql_mgmt_client_enums.py | 28 + .../models/_models_py3.py | 199 ++++-- .../operations/_clusters_operations.py | 581 +++++++----------- .../operations/_configurations_operations.py | 298 +++------ .../operations/_firewall_rules_operations.py | 198 +++--- .../operations/_operations.py | 37 +- ...private_endpoint_connections_operations.py | 199 +++--- .../_private_link_resources_operations.py | 60 +- .../operations/_roles_operations.py | 198 +++--- .../operations/_servers_operations.py | 60 +- .../check_name_availability.py | 1 + .../generated_samples/cluster_add_node.py | 1 + .../cluster_create_burstablev1.py | 1 + .../cluster_create_burstablev2.py | 1 + .../cluster_create_custom_database_name.py | 60 ++ .../cluster_create_multi_node.py | 1 + .../generated_samples/cluster_create_pitr.py | 1 + .../cluster_create_read_replica.py | 1 + .../cluster_create_single_node.py | 1 + .../cluster_create_with_aad.py | 75 +++ .../cluster_create_with_cmk.py | 75 +++ .../generated_samples/cluster_delete.py | 1 + .../generated_samples/cluster_get.py | 1 + .../generated_samples/cluster_list.py | 1 + .../cluster_list_by_resource_group.py | 1 + .../cluster_promote_read_replica.py | 1 + .../generated_samples/cluster_restart.py | 1 + .../cluster_scale_compute.py | 1 + .../cluster_scale_storage.py | 1 + .../generated_samples/cluster_start.py | 1 + .../generated_samples/cluster_stop.py | 1 + .../generated_samples/cluster_update.py | 1 + .../cluster_update_maintenance_window.py | 1 + .../generated_samples/configuration_get.py | 1 + .../configuration_get_coordinator.py | 1 + .../configuration_get_node.py | 1 + .../configuration_list_by_cluster.py | 1 + .../configuration_list_by_server.py | 1 + .../configuration_update_coordinator.py | 1 + .../configuration_update_node.py | 1 + .../generated_samples/firewall_rule_create.py | 1 + .../generated_samples/firewall_rule_delete.py | 1 + .../generated_samples/firewall_rule_get.py | 1 + .../firewall_rule_list_by_cluster.py | 1 + .../generated_samples/operation_list.py | 1 + ...te_endpoint_connection_create_or_update.py | 1 + .../private_endpoint_connections_delete.py | 1 + .../private_endpoint_connections_get.py | 1 + ...te_endpoint_connections_list_by_cluster.py | 1 + .../private_link_resource_list_by_cluster.py | 1 + .../private_link_resources_get.py | 1 + .../generated_samples/role_create.py | 1 + .../generated_samples/role_delete.py | 1 + .../generated_samples/role_get.py | 1 + .../generated_samples/role_list_by_cluster.py | 1 + .../generated_samples/server_get.py | 1 + .../server_list_by_cluster.py | 1 + .../generated_tests/conftest.py | 43 ++ ...for_postgresql_mgmt_clusters_operations.py | 242 ++++++++ ...stgresql_mgmt_clusters_operations_async.py | 257 ++++++++ ...stgresql_mgmt_configurations_operations.py | 151 +++++ ...ql_mgmt_configurations_operations_async.py | 156 +++++ ...stgresql_mgmt_firewall_rules_operations.py | 86 +++ ...ql_mgmt_firewall_rules_operations_async.py | 91 +++ ...cosmosdb_for_postgresql_mgmt_operations.py | 29 + ...db_for_postgresql_mgmt_operations_async.py | 30 + ...private_endpoint_connections_operations.py | 87 +++ ...e_endpoint_connections_operations_async.py | 96 +++ ..._mgmt_private_link_resources_operations.py | 44 ++ ...private_link_resources_operations_async.py | 45 ++ ...db_for_postgresql_mgmt_roles_operations.py | 89 +++ ..._postgresql_mgmt_roles_operations_async.py | 94 +++ ..._for_postgresql_mgmt_servers_operations.py | 44 ++ ...ostgresql_mgmt_servers_operations_async.py | 45 ++ .../azure-mgmt-cosmosdbforpostgresql/setup.py | 7 +- 91 files changed, 3400 insertions(+), 2173 deletions(-) create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_custom_database_name.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_with_aad.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_with_cmk.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/conftest.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_clusters_operations.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_clusters_operations_async.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_configurations_operations.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_configurations_operations_async.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_firewall_rules_operations.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_firewall_rules_operations_async.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_operations.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_operations_async.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_endpoint_connections_operations.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_endpoint_connections_operations_async.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_link_resources_operations.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_link_resources_operations_async.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_roles_operations.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_roles_operations_async.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_servers_operations.py create mode 100644 sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_servers_operations_async.py diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/_meta.json b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/_meta.json index e0a3d24a5bc7..3e8208110c17 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/_meta.json +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/_meta.json @@ -1,11 +1,11 @@ { - "commit": "77df3b1680a95566a3e6a3a2cd07c9a4960b2af3", + "commit": "7e1efd5a7d7535dbfb4b7144a643af19118bb923", "repository_url": "https://github.com/Azure/azure-rest-api-specs", - "autorest": "3.9.7", + "autorest": "3.10.2", "use": [ - "@autorest/python@6.7.1", - "@autorest/modelerfour@4.26.2" + "@autorest/python@6.19.0", + "@autorest/modelerfour@4.27.0" ], - "autorest_command": "autorest specification/postgresqlhsc/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/home/vsts/work/1/azure-sdk-for-python/sdk --use=@autorest/python@6.7.1 --use=@autorest/modelerfour@4.26.2 --version=3.9.7 --version-tolerant=False", + "autorest_command": "autorest specification/postgresqlhsc/resource-manager/readme.md --generate-sample=True --generate-test=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/mnt/vss/_work/1/s/azure-sdk-for-python/sdk --use=@autorest/python@6.19.0 --use=@autorest/modelerfour@4.27.0 --version=3.10.2 --version-tolerant=False", "readme": "specification/postgresqlhsc/resource-manager/readme.md" } \ No newline at end of file diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_configuration.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_configuration.py index a51af0fc9279..d6f0f498b9a3 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_configuration.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_configuration.py @@ -8,7 +8,6 @@ from typing import Any, TYPE_CHECKING -from azure.core.configuration import Configuration from azure.core.pipeline import policies from azure.mgmt.core.policies import ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy @@ -19,7 +18,7 @@ from azure.core.credentials import TokenCredential -class CosmosdbForPostgresqlMgmtClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes +class CosmosdbForPostgresqlMgmtClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long """Configuration for CosmosdbForPostgresqlMgmtClient. Note that all parameters used to create this instance are saved as instance @@ -35,7 +34,6 @@ class CosmosdbForPostgresqlMgmtClientConfiguration(Configuration): # pylint: di """ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: - super(CosmosdbForPostgresqlMgmtClientConfiguration, self).__init__(**kwargs) api_version: str = kwargs.pop("api_version", "2023-03-02-preview") if credential is None: @@ -48,6 +46,7 @@ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-cosmosdbforpostgresql/{}".format(VERSION)) + self.polling_interval = kwargs.get("polling_interval", 30) self._configure(**kwargs) def _configure(self, **kwargs: Any) -> None: @@ -56,9 +55,9 @@ def _configure(self, **kwargs: Any) -> None: self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) self.http_logging_policy = kwargs.get("http_logging_policy") or ARMHttpLoggingPolicy(**kwargs) - self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) self.authentication_policy = kwargs.get("authentication_policy") if self.credential and not self.authentication_policy: self.authentication_policy = ARMChallengeAuthenticationPolicy( diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_cosmosdb_for_postgresql_mgmt_client.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_cosmosdb_for_postgresql_mgmt_client.py index 5257232629b3..a66d4c585ca3 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_cosmosdb_for_postgresql_mgmt_client.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_cosmosdb_for_postgresql_mgmt_client.py @@ -8,9 +8,12 @@ from copy import deepcopy from typing import Any, TYPE_CHECKING +from typing_extensions import Self +from azure.core.pipeline import policies from azure.core.rest import HttpRequest, HttpResponse from azure.mgmt.core import ARMPipelineClient +from azure.mgmt.core.policies import ARMAutoResourceProviderRegistrationPolicy from . import models as _models from ._configuration import CosmosdbForPostgresqlMgmtClientConfiguration @@ -75,7 +78,25 @@ def __init__( self._config = CosmosdbForPostgresqlMgmtClientConfiguration( credential=credential, subscription_id=subscription_id, **kwargs ) - self._client: ARMPipelineClient = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs) + _policies = kwargs.pop("policies", None) + if _policies is None: + _policies = [ + policies.RequestIdPolicy(**kwargs), + self._config.headers_policy, + self._config.user_agent_policy, + self._config.proxy_policy, + policies.ContentDecodePolicy(**kwargs), + ARMAutoResourceProviderRegistrationPolicy(), + self._config.redirect_policy, + self._config.retry_policy, + self._config.authentication_policy, + self._config.custom_hook_policy, + self._config.logging_policy, + policies.DistributedTracingPolicy(**kwargs), + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, + self._config.http_logging_policy, + ] + self._client: ARMPipelineClient = ARMPipelineClient(base_url=base_url, policies=_policies, **kwargs) client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} self._serialize = Serializer(client_models) @@ -94,7 +115,7 @@ def __init__( self._client, self._config, self._serialize, self._deserialize ) - def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: + def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest @@ -114,12 +135,12 @@ def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: request_copy = deepcopy(request) request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore def close(self) -> None: self._client.close() - def __enter__(self) -> "CosmosdbForPostgresqlMgmtClient": + def __enter__(self) -> Self: self._client.__enter__() return self diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_serialization.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_serialization.py index 4bae2292227b..8139854b97bb 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_serialization.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_serialization.py @@ -63,8 +63,8 @@ import isodate # type: ignore -from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback -from azure.core.serialization import NULL as AzureCoreNull +from azure.core.exceptions import DeserializationError, SerializationError +from azure.core.serialization import NULL as CoreNull _BOM = codecs.BOM_UTF8.decode(encoding="utf-8") @@ -124,7 +124,7 @@ def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type: pass return ET.fromstring(data_as_str) # nosec - except ET.ParseError: + except ET.ParseError as err: # It might be because the server has an issue, and returned JSON with # content-type XML.... # So let's try a JSON load, and if it's still broken @@ -143,7 +143,9 @@ def _json_attemp(data): # The function hack is because Py2.7 messes up with exception # context otherwise. _LOGGER.critical("Wasn't XML not JSON, failing") - raise_with_traceback(DeserializationError, "XML is invalid") + raise DeserializationError("XML is invalid") from err + elif content_type.startswith("text/"): + return data_as_str raise DeserializationError("Cannot deserialize content-type: {}".format(content_type)) @classmethod @@ -170,13 +172,6 @@ def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]], return None -try: - basestring # type: ignore - unicode_str = unicode # type: ignore -except NameError: - basestring = str - unicode_str = str - _LOGGER = logging.getLogger(__name__) try: @@ -295,7 +290,7 @@ class Model(object): _validation: Dict[str, Dict[str, Any]] = {} def __init__(self, **kwargs: Any) -> None: - self.additional_properties: Dict[str, Any] = {} + self.additional_properties: Optional[Dict[str, Any]] = {} for k in kwargs: if k not in self._attribute_map: _LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__) @@ -340,7 +335,7 @@ def _create_xml_node(cls): return _create_xml_node(xml_map.get("name", cls.__name__), xml_map.get("prefix", None), xml_map.get("ns", None)) def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON: - """Return the JSON that would be sent to azure from this model. + """Return the JSON that would be sent to server from this model. This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`. @@ -351,7 +346,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON: :rtype: dict """ serializer = Serializer(self._infer_class_models()) - return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) + return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) # type: ignore def as_dict( self, @@ -390,7 +385,7 @@ def my_key_transformer(key, attr_desc, value): :rtype: dict """ serializer = Serializer(self._infer_class_models()) - return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) + return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def _infer_class_models(cls): @@ -415,7 +410,7 @@ def deserialize(cls: Type[ModelType], data: Any, content_type: Optional[str] = N :raises: DeserializationError if something went wrong """ deserializer = Deserializer(cls._infer_class_models()) - return deserializer(cls.__name__, data, content_type=content_type) + return deserializer(cls.__name__, data, content_type=content_type) # type: ignore @classmethod def from_dict( @@ -445,7 +440,7 @@ def from_dict( if key_extractors is None else key_extractors ) - return deserializer(cls.__name__, data, content_type=content_type) + return deserializer(cls.__name__, data, content_type=content_type) # type: ignore @classmethod def _flatten_subtype(cls, key, objects): @@ -545,7 +540,7 @@ class Serializer(object): "multiple": lambda x, y: x % y != 0, } - def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None): + def __init__(self, classes: Optional[Mapping[str, type]] = None): self.serialize_type = { "iso-8601": Serializer.serialize_iso, "rfc-1123": Serializer.serialize_rfc, @@ -561,7 +556,7 @@ def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None): "[]": self.serialize_iter, "{}": self.serialize_dict, } - self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {} + self.dependencies: Dict[str, type] = dict(classes) if classes else {} self.key_transformer = full_restapi_key_transformer self.client_side_validation = True @@ -649,7 +644,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs): 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) + local_node.text = str(new_attr) serialized.append(local_node) # type: ignore else: # JSON for k in reversed(keys): # type: ignore @@ -668,7 +663,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs): except (AttributeError, KeyError, TypeError) as err: msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj)) - raise_with_traceback(SerializationError, msg, err) + raise SerializationError(msg) from err else: return serialized @@ -710,7 +705,7 @@ def body(self, data, data_type, **kwargs): ] data = deserializer._deserialize(data_type, data) except DeserializationError as err: - raise_with_traceback(SerializationError, "Unable to build a model: " + str(err), err) + raise SerializationError("Unable to build a model: " + str(err)) from err return self._serialize(data, data_type, **kwargs) @@ -730,6 +725,7 @@ def url(self, name, data, data_type, **kwargs): if kwargs.get("skip_quote") is True: output = str(output) + output = output.replace("{", quote("{")).replace("}", quote("}")) else: output = quote(str(output), safe="") except SerializationError: @@ -744,7 +740,7 @@ def query(self, name, data, data_type, **kwargs): :param str data_type: The type to be serialized from. :keyword bool skip_quote: Whether to skip quote the serialized result. Defaults to False. - :rtype: str + :rtype: str, list :raises: TypeError if serialization fails. :raises: ValueError if data is None """ @@ -753,7 +749,7 @@ def query(self, name, data, data_type, **kwargs): if data_type.startswith("["): internal_data_type = data_type[1:-1] do_quote = not kwargs.get("skip_quote", False) - return str(self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs)) + return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs) # Not a list, regular serialization output = self.serialize_data(data, data_type, **kwargs) @@ -804,7 +800,7 @@ def serialize_data(self, data, data_type, **kwargs): raise ValueError("No value for given attribute") try: - if data is AzureCoreNull: + if data is CoreNull: return None if data_type in self.basic_types.values(): return self.serialize_basic(data, data_type, **kwargs) @@ -824,7 +820,7 @@ def serialize_data(self, data, data_type, **kwargs): except (ValueError, TypeError) as err: msg = "Unable to serialize value: {!r} as type: {!r}." - raise_with_traceback(SerializationError, msg.format(data, data_type), err) + raise SerializationError(msg.format(data, data_type)) from err else: return self._serialize(data, **kwargs) @@ -993,7 +989,7 @@ def serialize_object(self, attr, **kwargs): return self.serialize_basic(attr, self.basic_types[obj_type], **kwargs) if obj_type is _long_type: return self.serialize_long(attr) - if obj_type is unicode_str: + if obj_type is str: return self.serialize_unicode(attr) if obj_type is datetime.datetime: return self.serialize_iso(attr) @@ -1170,10 +1166,10 @@ def serialize_iso(attr, **kwargs): return date + microseconds + "Z" except (ValueError, OverflowError) as err: msg = "Unable to serialize datetime object." - raise_with_traceback(SerializationError, msg, err) + raise SerializationError(msg) from err except AttributeError as err: msg = "ISO-8601 object must be valid Datetime object." - raise_with_traceback(TypeError, msg, err) + raise TypeError(msg) from err @staticmethod def serialize_unix(attr, **kwargs): @@ -1209,7 +1205,6 @@ def rest_key_extractor(attr, attr_desc, data): if working_data is None: # If at any point while following flatten JSON path see None, it means # that all properties under are None as well - # https://github.com/Azure/msrest-for-python/issues/197 return None key = ".".join(dict_keys[1:]) @@ -1230,7 +1225,6 @@ def rest_key_case_insensitive_extractor(attr, attr_desc, data): if working_data is None: # If at any point while following flatten JSON path see None, it means # that all properties under are None as well - # https://github.com/Azure/msrest-for-python/issues/197 return None key = ".".join(dict_keys[1:]) @@ -1371,7 +1365,7 @@ class Deserializer(object): valid_date = re.compile(r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}" r"\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?") - def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None): + def __init__(self, classes: Optional[Mapping[str, type]] = None): self.deserialize_type = { "iso-8601": Deserializer.deserialize_iso, "rfc-1123": Deserializer.deserialize_rfc, @@ -1391,7 +1385,7 @@ def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None): "duration": (isodate.Duration, datetime.timedelta), "iso-8601": (datetime.datetime), } - self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {} + self.dependencies: Dict[str, type] = dict(classes) if classes else {} self.key_extractors = [rest_key_extractor, xml_key_extractor] # Additional properties only works if the "rest_key_extractor" is used to # extract the keys. Making it to work whatever the key extractor is too much @@ -1444,12 +1438,12 @@ def _deserialize(self, target_obj, data): response, class_name = self._classify_target(target_obj, data) - if isinstance(response, basestring): + if isinstance(response, str): return self.deserialize_data(data, response) elif isinstance(response, type) and issubclass(response, Enum): return self.deserialize_enum(data, response) - if data is None: + if data is None or data is CoreNull: return data try: attributes = response._attribute_map # type: ignore @@ -1481,7 +1475,7 @@ def _deserialize(self, target_obj, data): d_attrs[attr] = value except (AttributeError, TypeError, KeyError) as err: msg = "Unable to deserialize to object: " + class_name # type: ignore - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: additional_properties = self._build_additional_properties(attributes, data) return self._instantiate_model(response, d_attrs, additional_properties) @@ -1515,14 +1509,14 @@ def _classify_target(self, target, data): if target is None: return None, None - if isinstance(target, basestring): + if isinstance(target, str): try: target = self.dependencies[target] except KeyError: return target, target try: - target = target._classify(data, self.dependencies) + target = target._classify(data, self.dependencies) # type: ignore except AttributeError: pass # Target is not a Model, no classify return target, target.__class__.__name__ # type: ignore @@ -1578,7 +1572,7 @@ def _unpack_content(raw_data, content_type=None): if hasattr(raw_data, "_content_consumed"): return RawDeserializer.deserialize_from_http_generics(raw_data.text, raw_data.headers) - if isinstance(raw_data, (basestring, bytes)) or hasattr(raw_data, "read"): + if isinstance(raw_data, (str, bytes)) or hasattr(raw_data, "read"): return RawDeserializer.deserialize_from_text(raw_data, content_type) # type: ignore return raw_data @@ -1652,7 +1646,7 @@ def deserialize_data(self, data, data_type): except (ValueError, TypeError, AttributeError) as err: msg = "Unable to deserialize response data." msg += " Data: {}, {}".format(data, data_type) - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return self._deserialize(obj_type, data) @@ -1700,7 +1694,7 @@ def deserialize_object(self, attr, **kwargs): if isinstance(attr, ET.Element): # Do no recurse on XML, just return the tree as-is return attr - if isinstance(attr, basestring): + if isinstance(attr, str): return self.deserialize_basic(attr, "str") obj_type = type(attr) if obj_type in self.basic_types: @@ -1757,7 +1751,7 @@ def deserialize_basic(self, attr, data_type): if data_type == "bool": if attr in [True, False, 1, 0]: return bool(attr) - elif isinstance(attr, basestring): + elif isinstance(attr, str): if attr.lower() in ["true", "1"]: return True elif attr.lower() in ["false", "0"]: @@ -1808,7 +1802,6 @@ def deserialize_enum(data, enum_obj): data = data.value if isinstance(data, int): # Workaround. We might consider remove it in the future. - # https://github.com/Azure/azure-rest-api-specs/issues/141 try: return list(enum_obj.__members__.values())[data] except IndexError: @@ -1862,10 +1855,10 @@ def deserialize_decimal(attr): if isinstance(attr, ET.Element): attr = attr.text try: - return decimal.Decimal(attr) # type: ignore + return decimal.Decimal(str(attr)) # type: ignore except decimal.DecimalException as err: msg = "Invalid decimal {}".format(attr) - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err @staticmethod def deserialize_long(attr): @@ -1893,7 +1886,7 @@ def deserialize_duration(attr): duration = isodate.parse_duration(attr) except (ValueError, OverflowError, AttributeError) as err: msg = "Cannot deserialize duration object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return duration @@ -1910,7 +1903,7 @@ def deserialize_date(attr): if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore raise DeserializationError("Date must have only digits and -. Received: %s" % attr) # This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception. - return isodate.parse_date(attr, defaultmonth=None, defaultday=None) + return isodate.parse_date(attr, defaultmonth=0, defaultday=0) @staticmethod def deserialize_time(attr): @@ -1945,7 +1938,7 @@ def deserialize_rfc(attr): date_obj = date_obj.astimezone(tz=TZ_UTC) except ValueError as err: msg = "Cannot deserialize to rfc datetime object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return date_obj @@ -1982,7 +1975,7 @@ def deserialize_iso(attr): raise OverflowError("Hit max or min date") except (ValueError, OverflowError, AttributeError) as err: msg = "Cannot deserialize datetime object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return date_obj @@ -1998,9 +1991,10 @@ def deserialize_unix(attr): if isinstance(attr, ET.Element): attr = int(attr.text) # type: ignore try: + attr = int(attr) date_obj = datetime.datetime.fromtimestamp(attr, TZ_UTC) except ValueError as err: msg = "Cannot deserialize to unix datetime object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return date_obj diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_version.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_version.py index 653b73a4a199..e5754a47ce68 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_version.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "1.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/_configuration.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/_configuration.py index 7f538b80b481..6be7beee64fe 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/_configuration.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/_configuration.py @@ -8,7 +8,6 @@ from typing import Any, TYPE_CHECKING -from azure.core.configuration import Configuration from azure.core.pipeline import policies from azure.mgmt.core.policies import ARMHttpLoggingPolicy, AsyncARMChallengeAuthenticationPolicy @@ -19,7 +18,7 @@ from azure.core.credentials_async import AsyncTokenCredential -class CosmosdbForPostgresqlMgmtClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes +class CosmosdbForPostgresqlMgmtClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long """Configuration for CosmosdbForPostgresqlMgmtClient. Note that all parameters used to create this instance are saved as instance @@ -35,7 +34,6 @@ class CosmosdbForPostgresqlMgmtClientConfiguration(Configuration): # pylint: di """ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: - super(CosmosdbForPostgresqlMgmtClientConfiguration, self).__init__(**kwargs) api_version: str = kwargs.pop("api_version", "2023-03-02-preview") if credential is None: @@ -48,6 +46,7 @@ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **k self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-cosmosdbforpostgresql/{}".format(VERSION)) + self.polling_interval = kwargs.get("polling_interval", 30) self._configure(**kwargs) def _configure(self, **kwargs: Any) -> None: @@ -56,9 +55,9 @@ def _configure(self, **kwargs: Any) -> None: self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) self.http_logging_policy = kwargs.get("http_logging_policy") or ARMHttpLoggingPolicy(**kwargs) - self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) self.authentication_policy = kwargs.get("authentication_policy") if self.credential and not self.authentication_policy: self.authentication_policy = AsyncARMChallengeAuthenticationPolicy( diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/_cosmosdb_for_postgresql_mgmt_client.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/_cosmosdb_for_postgresql_mgmt_client.py index c895dcec681f..4c0b74c3a5bb 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/_cosmosdb_for_postgresql_mgmt_client.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/_cosmosdb_for_postgresql_mgmt_client.py @@ -8,9 +8,12 @@ from copy import deepcopy from typing import Any, Awaitable, TYPE_CHECKING +from typing_extensions import Self +from azure.core.pipeline import policies from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.mgmt.core import AsyncARMPipelineClient +from azure.mgmt.core.policies import AsyncARMAutoResourceProviderRegistrationPolicy from .. import models as _models from .._serialization import Deserializer, Serializer @@ -77,7 +80,25 @@ def __init__( self._config = CosmosdbForPostgresqlMgmtClientConfiguration( credential=credential, subscription_id=subscription_id, **kwargs ) - self._client: AsyncARMPipelineClient = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs) + _policies = kwargs.pop("policies", None) + if _policies is None: + _policies = [ + policies.RequestIdPolicy(**kwargs), + self._config.headers_policy, + self._config.user_agent_policy, + self._config.proxy_policy, + policies.ContentDecodePolicy(**kwargs), + AsyncARMAutoResourceProviderRegistrationPolicy(), + self._config.redirect_policy, + self._config.retry_policy, + self._config.authentication_policy, + self._config.custom_hook_policy, + self._config.logging_policy, + policies.DistributedTracingPolicy(**kwargs), + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, + self._config.http_logging_policy, + ] + self._client: AsyncARMPipelineClient = AsyncARMPipelineClient(base_url=base_url, policies=_policies, **kwargs) client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} self._serialize = Serializer(client_models) @@ -96,7 +117,9 @@ def __init__( self._client, self._config, self._serialize, self._deserialize ) - def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: + def _send_request( + self, request: HttpRequest, *, stream: bool = False, **kwargs: Any + ) -> Awaitable[AsyncHttpResponse]: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest @@ -116,12 +139,12 @@ def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncH request_copy = deepcopy(request) request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore async def close(self) -> None: await self._client.close() - async def __aenter__(self) -> "CosmosdbForPostgresqlMgmtClient": + async def __aenter__(self) -> Self: await self._client.__aenter__() return self diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_clusters_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_clusters_operations.py index dcca4f991d2c..ec42b1b6f584 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_clusters_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_clusters_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._clusters_operations import ( build_check_name_availability_request, build_create_request, @@ -45,6 +46,10 @@ build_update_request, ) +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -72,7 +77,6 @@ def __init__(self, *args, **kwargs) -> None: def list(self, **kwargs: Any) -> AsyncIterable["_models.Cluster"]: """Lists all clusters in a subscription. - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Cluster or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] @@ -84,7 +88,7 @@ def list(self, **kwargs: Any) -> AsyncIterable["_models.Cluster"]: api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -95,15 +99,13 @@ def list(self, **kwargs: Any) -> AsyncIterable["_models.Cluster"]: def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -115,13 +117,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ClusterListResult", pipeline_response) @@ -131,11 +132,11 @@ async def extract_data(pipeline_response): return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -148,8 +149,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2"} - @distributed_trace def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> AsyncIterable["_models.Cluster"]: """Lists all clusters in a resource group. @@ -157,7 +156,6 @@ def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> Asy :param resource_group_name: The name of the resource group. The name is case insensitive. Required. :type resource_group_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Cluster or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] @@ -169,7 +167,7 @@ def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> Asy api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -180,16 +178,14 @@ def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> Asy def prepare_request(next_link=None): if not next_link: - request = build_list_by_resource_group_request( + _request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -201,13 +197,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ClusterListResult", pipeline_response) @@ -217,11 +212,11 @@ async def extract_data(pipeline_response): return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -234,14 +229,10 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2" - } - async def _create_initial( - self, resource_group_name: str, cluster_name: str, parameters: Union[_models.Cluster, IO], **kwargs: Any - ) -> _models.Cluster: - error_map = { + self, resource_group_name: str, cluster_name: str, parameters: Union[_models.Cluster, IO[bytes]], **kwargs: Any + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -254,7 +245,7 @@ async def _create_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Cluster] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -264,7 +255,7 @@ async def _create_initial( else: _json = self._serialize.body(parameters, "Cluster") - request = build_create_request( + _request = build_create_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, @@ -272,46 +263,42 @@ async def _create_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("Cluster", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _create_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } - @overload async def begin_create( self, @@ -334,14 +321,6 @@ async def begin_create( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A 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 Cluster or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] @@ -353,7 +332,7 @@ async def begin_create( self, resource_group_name: str, cluster_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -366,18 +345,10 @@ async def begin_create( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param parameters: The required parameters for creating or updating a cluster. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] @@ -386,7 +357,7 @@ async def begin_create( @distributed_trace_async async def begin_create( - self, resource_group_name: str, cluster_name: str, parameters: Union[_models.Cluster, IO], **kwargs: Any + self, resource_group_name: str, cluster_name: str, parameters: Union[_models.Cluster, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.Cluster]: """Creates a new cluster with servers. @@ -396,19 +367,8 @@ async def begin_create( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param parameters: The required parameters for creating or updating a cluster. Is either a - Cluster type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.Cluster or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + Cluster type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.Cluster or IO[bytes] :return: An instance of AsyncLROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] @@ -435,12 +395,13 @@ async def begin_create( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = self._deserialize("Cluster", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -453,17 +414,15 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.Cluster].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) # type: ignore - - begin_create.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return AsyncLROPoller[_models.Cluster]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) @distributed_trace_async async def get(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> _models.Cluster: @@ -475,12 +434,11 @@ async def get(self, resource_group_name: str, cluster_name: str, **kwargs: Any) :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Cluster or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.Cluster :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -494,21 +452,19 @@ async def get(self, resource_group_name: str, cluster_name: str, **kwargs: Any) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.Cluster] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -518,21 +474,15 @@ async def get(self, resource_group_name: str, cluster_name: str, **kwargs: Any) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = self._deserialize("Cluster", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return deserialized # type: ignore - async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, cluster_name: str, **kwargs: Any - ) -> None: - error_map = { + async def _delete_initial(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -544,28 +494,31 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -577,12 +530,12 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _delete_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return deserialized # type: ignore @distributed_trace_async async def begin_delete(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> AsyncLROPoller[None]: @@ -593,14 +546,6 @@ async def begin_delete(self, resource_group_name: str, cluster_name: str, **kwar :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -614,7 +559,7 @@ async def begin_delete(self, resource_group_name: str, cluster_name: str, **kwar lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, api_version=api_version, @@ -623,11 +568,12 @@ async def begin_delete(self, resource_group_name: str, cluster_name: str, **kwar params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: AsyncPollingMethod = cast( @@ -638,26 +584,22 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_delete.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore async def _update_initial( self, resource_group_name: str, cluster_name: str, - parameters: Union[_models.ClusterForUpdate, IO], + parameters: Union[_models.ClusterForUpdate, IO[bytes]], **kwargs: Any - ) -> _models.Cluster: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -670,7 +612,7 @@ async def _update_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Cluster] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -680,7 +622,7 @@ async def _update_initial( else: _json = self._serialize.body(parameters, "ClusterForUpdate") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, @@ -688,46 +630,42 @@ async def _update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("Cluster", pipeline_response) - if response.status_code == 202: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _update_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } - @overload async def begin_update( self, @@ -751,14 +689,6 @@ async def begin_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] @@ -770,7 +700,7 @@ async def begin_update( self, resource_group_name: str, cluster_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -784,18 +714,10 @@ async def begin_update( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param parameters: The parameters for updating a cluster. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] @@ -807,7 +729,7 @@ async def begin_update( self, resource_group_name: str, cluster_name: str, - parameters: Union[_models.ClusterForUpdate, IO], + parameters: Union[_models.ClusterForUpdate, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.Cluster]: """Updates an existing cluster. The request body can contain one or several properties from the @@ -819,19 +741,8 @@ async def begin_update( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param parameters: The parameters for updating a cluster. Is either a ClusterForUpdate type or - a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ClusterForUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ClusterForUpdate or IO[bytes] :return: An instance of AsyncLROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] @@ -858,12 +769,13 @@ async def begin_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = self._deserialize("Cluster", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -875,22 +787,20 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.Cluster].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) # type: ignore - - begin_update.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return AsyncLROPoller[_models.Cluster]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _restart_initial( # pylint: disable=inconsistent-return-statements + async def _restart_initial( self, resource_group_name: str, cluster_name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -902,28 +812,31 @@ async def _restart_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_restart_request( + _request = build_restart_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._restart_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -934,12 +847,12 @@ async def _restart_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _restart_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/restart" - } + return deserialized # type: ignore @distributed_trace_async async def begin_restart(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> AsyncLROPoller[None]: @@ -950,14 +863,6 @@ async def begin_restart(self, resource_group_name: str, cluster_name: str, **kwa :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -971,7 +876,7 @@ async def begin_restart(self, resource_group_name: str, cluster_name: str, **kwa lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._restart_initial( # type: ignore + raw_result = await self._restart_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, api_version=api_version, @@ -980,11 +885,12 @@ async def begin_restart(self, resource_group_name: str, cluster_name: str, **kwa params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: AsyncPollingMethod = cast( @@ -995,22 +901,16 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_restart.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/restart" - } - - async def _start_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, cluster_name: str, **kwargs: Any - ) -> None: - error_map = { + async def _start_initial(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1022,28 +922,31 @@ async def _start_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_start_request( + _request = build_start_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._start_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -1055,12 +958,12 @@ async def _start_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _start_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/start" - } + return deserialized # type: ignore @distributed_trace_async async def begin_start(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> AsyncLROPoller[None]: @@ -1071,14 +974,6 @@ async def begin_start(self, resource_group_name: str, cluster_name: str, **kwarg :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1092,7 +987,7 @@ async def begin_start(self, resource_group_name: str, cluster_name: str, **kwarg lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._start_initial( # type: ignore + raw_result = await self._start_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, api_version=api_version, @@ -1101,11 +996,12 @@ async def begin_start(self, resource_group_name: str, cluster_name: str, **kwarg params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: AsyncPollingMethod = cast( @@ -1116,22 +1012,16 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_start.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/start" - } - - async def _stop_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, cluster_name: str, **kwargs: Any - ) -> None: - error_map = { + async def _stop_initial(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1143,28 +1033,31 @@ async def _stop_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_stop_request( + _request = build_stop_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._stop_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -1176,12 +1069,12 @@ async def _stop_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _stop_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/stop" - } + return deserialized # type: ignore @distributed_trace_async async def begin_stop(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> AsyncLROPoller[None]: @@ -1192,14 +1085,6 @@ async def begin_stop(self, resource_group_name: str, cluster_name: str, **kwargs :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1213,7 +1098,7 @@ async def begin_stop(self, resource_group_name: str, cluster_name: str, **kwargs lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._stop_initial( # type: ignore + raw_result = await self._stop_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, api_version=api_version, @@ -1222,11 +1107,12 @@ async def begin_stop(self, resource_group_name: str, cluster_name: str, **kwargs params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: AsyncPollingMethod = cast( @@ -1237,26 +1123,22 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_stop.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/stop" - } - - async def _promote_read_replica_initial( # pylint: disable=inconsistent-return-statements + async def _promote_read_replica_initial( self, resource_group_name: str, cluster_name: str, - promote_request: Optional[Union[_models.PromoteRequest, IO]] = None, + promote_request: Optional[Union[_models.PromoteRequest, IO[bytes]]] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1269,7 +1151,7 @@ async def _promote_read_replica_initial( # pylint: disable=inconsistent-return- api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -1282,7 +1164,7 @@ async def _promote_read_replica_initial( # pylint: disable=inconsistent-return- else: _json = None - request = build_promote_read_replica_request( + _request = build_promote_read_replica_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, @@ -1290,21 +1172,24 @@ async def _promote_read_replica_initial( # pylint: disable=inconsistent-return- content_type=content_type, json=_json, content=_content, - template_url=self._promote_read_replica_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -1315,12 +1200,12 @@ async def _promote_read_replica_initial( # pylint: disable=inconsistent-return- "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _promote_read_replica_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/promote" - } + return deserialized # type: ignore @overload async def begin_promote_read_replica( @@ -1345,14 +1230,6 @@ async def begin_promote_read_replica( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A 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: @@ -1363,7 +1240,7 @@ async def begin_promote_read_replica( self, resource_group_name: str, cluster_name: str, - promote_request: Optional[IO] = None, + promote_request: Optional[IO[bytes]] = None, *, content_type: str = "application/json", **kwargs: Any @@ -1377,18 +1254,10 @@ async def begin_promote_read_replica( :type cluster_name: str :param promote_request: The parameter for enabling geo-redundant backup while promoting read replica. Default value is None. - :type promote_request: IO + :type promote_request: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A 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: @@ -1399,7 +1268,7 @@ async def begin_promote_read_replica( self, resource_group_name: str, cluster_name: str, - promote_request: Optional[Union[_models.PromoteRequest, IO]] = None, + promote_request: Optional[Union[_models.PromoteRequest, IO[bytes]]] = None, **kwargs: Any ) -> AsyncLROPoller[None]: """Promotes read replica cluster to an independent read-write cluster. @@ -1410,19 +1279,8 @@ async def begin_promote_read_replica( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param promote_request: The parameter for enabling geo-redundant backup while promoting read - replica. Is either a PromoteRequest type or a IO type. Default value is None. - :type promote_request: ~azure.mgmt.cosmosdbforpostgresql.models.PromoteRequest or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + replica. Is either a PromoteRequest type or a IO[bytes] type. Default value is None. + :type promote_request: ~azure.mgmt.cosmosdbforpostgresql.models.PromoteRequest or IO[bytes] :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1437,7 +1295,7 @@ async def begin_promote_read_replica( lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._promote_read_replica_initial( # type: ignore + raw_result = await self._promote_read_replica_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, promote_request=promote_request, @@ -1448,11 +1306,12 @@ async def begin_promote_read_replica( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: AsyncPollingMethod = cast( @@ -1463,17 +1322,13 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_promote_read_replica.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/promote" - } + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @overload async def check_name_availability( @@ -1494,7 +1349,6 @@ async def check_name_availability( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. 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: NameAvailability or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailability :raises ~azure.core.exceptions.HttpResponseError: @@ -1502,7 +1356,7 @@ async def check_name_availability( @overload async def check_name_availability( - self, name_availability_request: IO, *, content_type: str = "application/json", **kwargs: Any + self, name_availability_request: IO[bytes], *, content_type: str = "application/json", **kwargs: Any ) -> _models.NameAvailability: """Checks availability of a cluster name. Cluster names should be globally unique; at least 3 characters and at most 40 characters long; they must only contain lowercase letters, numbers, @@ -1510,11 +1364,10 @@ async def check_name_availability( :param name_availability_request: The required parameters for checking if cluster name is available. Required. - :type name_availability_request: IO + :type name_availability_request: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: NameAvailability or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailability :raises ~azure.core.exceptions.HttpResponseError: @@ -1522,25 +1375,21 @@ async def check_name_availability( @distributed_trace_async async def check_name_availability( - self, name_availability_request: Union[_models.NameAvailabilityRequest, IO], **kwargs: Any + self, name_availability_request: Union[_models.NameAvailabilityRequest, IO[bytes]], **kwargs: Any ) -> _models.NameAvailability: """Checks availability of a cluster name. Cluster names should be globally unique; at least 3 characters and at most 40 characters long; they must only contain lowercase letters, numbers, and hyphens; and must not start or end with a hyphen. :param name_availability_request: The required parameters for checking if cluster name is - available. Is either a NameAvailabilityRequest type or a IO type. Required. + available. Is either a NameAvailabilityRequest type or a IO[bytes] type. Required. :type name_availability_request: - ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailabilityRequest or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailabilityRequest or IO[bytes] :return: NameAvailability or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailability :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1563,22 +1412,20 @@ async def check_name_availability( else: _json = self._serialize.body(name_availability_request, "NameAvailabilityRequest") - request = build_check_name_availability_request( + _request = build_check_name_availability_request( subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, content=_content, - template_url=self.check_name_availability.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1588,13 +1435,9 @@ async def check_name_availability( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("NameAvailability", pipeline_response) + deserialized = self._deserialize("NameAvailability", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - check_name_availability.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/checkNameAvailability" - } + return deserialized # type: ignore diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_configurations_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_configurations_operations.py index c4cc5c35475a..abc5b628137b 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_configurations_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_configurations_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._configurations_operations import ( build_get_coordinator_request, build_get_node_request, @@ -41,6 +42,10 @@ build_update_on_node_request, ) +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -77,7 +82,6 @@ def list_by_server( :type cluster_name: str :param server_name: The name of the server. Required. :type server_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ServerConfiguration or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration] @@ -89,7 +93,7 @@ def list_by_server( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ServerConfigurationListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -100,18 +104,16 @@ def list_by_server( def prepare_request(next_link=None): if not next_link: - request = build_list_by_server_request( + _request = build_list_by_server_request( resource_group_name=resource_group_name, cluster_name=cluster_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -123,13 +125,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ServerConfigurationListResult", pipeline_response) @@ -139,11 +140,11 @@ async def extract_data(pipeline_response): return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -156,10 +157,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_server.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers/{serverName}/configurations" - } - @distributed_trace def list_by_cluster( self, resource_group_name: str, cluster_name: str, **kwargs: Any @@ -171,7 +168,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Configuration or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Configuration] @@ -183,7 +179,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterConfigurationListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -194,17 +190,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -216,13 +210,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ClusterConfigurationListResult", pipeline_response) @@ -232,11 +225,11 @@ async def extract_data(pipeline_response): return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -249,10 +242,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/configurations" - } - @distributed_trace_async async def get( self, resource_group_name: str, cluster_name: str, configuration_name: str, **kwargs: Any @@ -266,12 +255,11 @@ async def get( :type cluster_name: str :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Configuration or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.Configuration :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -285,22 +273,20 @@ async def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.Configuration] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -310,16 +296,12 @@ async def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("Configuration", pipeline_response) + deserialized = self._deserialize("Configuration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/configurations/{configurationName}" - } + return deserialized # type: ignore @distributed_trace_async async def get_coordinator( @@ -334,12 +316,11 @@ async def get_coordinator( :type cluster_name: str :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServerConfiguration or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -353,22 +334,20 @@ async def get_coordinator( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ServerConfiguration] = kwargs.pop("cls", None) - request = build_get_coordinator_request( + _request = build_get_coordinator_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_coordinator.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -378,26 +357,22 @@ async def get_coordinator( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = self._deserialize("ServerConfiguration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get_coordinator.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/coordinatorConfigurations/{configurationName}" - } + return deserialized # type: ignore async def _update_on_coordinator_initial( self, resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: Union[_models.ServerConfiguration, IO], + parameters: Union[_models.ServerConfiguration, IO[bytes]], **kwargs: Any - ) -> _models.ServerConfiguration: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -410,7 +385,7 @@ async def _update_on_coordinator_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.ServerConfiguration] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -420,7 +395,7 @@ async def _update_on_coordinator_initial( else: _json = self._serialize.body(parameters, "ServerConfiguration") - request = build_update_on_coordinator_request( + _request = build_update_on_coordinator_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_name, @@ -429,46 +404,42 @@ async def _update_on_coordinator_initial( content_type=content_type, json=_json, content=_content, - template_url=self._update_on_coordinator_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("ServerConfiguration", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _update_on_coordinator_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/coordinatorConfigurations/{configurationName}" - } - @overload async def begin_update_on_coordinator( self, @@ -494,14 +465,6 @@ async def begin_update_on_coordinator( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A 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 ServerConfiguration or the result of cls(response) :rtype: @@ -515,7 +478,7 @@ async def begin_update_on_coordinator( resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -530,18 +493,10 @@ async def begin_update_on_coordinator( :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str :param parameters: The required parameters for updating a cluster configuration. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either ServerConfiguration or the result of cls(response) :rtype: @@ -555,7 +510,7 @@ async def begin_update_on_coordinator( resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: Union[_models.ServerConfiguration, IO], + parameters: Union[_models.ServerConfiguration, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.ServerConfiguration]: """Updates configuration of coordinator in a cluster. @@ -568,19 +523,8 @@ async def begin_update_on_coordinator( :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str :param parameters: The required parameters for updating a cluster configuration. Is either a - ServerConfiguration type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + ServerConfiguration type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration or IO[bytes] :return: An instance of AsyncLROPoller that returns either ServerConfiguration or the result of cls(response) :rtype: @@ -609,12 +553,13 @@ async def begin_update_on_coordinator( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = self._deserialize("ServerConfiguration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -627,17 +572,15 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.ServerConfiguration].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) # type: ignore - - begin_update_on_coordinator.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/coordinatorConfigurations/{configurationName}" - } + return AsyncLROPoller[_models.ServerConfiguration]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) @distributed_trace_async async def get_node( @@ -652,12 +595,11 @@ async def get_node( :type cluster_name: str :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServerConfiguration or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -671,22 +613,20 @@ async def get_node( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ServerConfiguration] = kwargs.pop("cls", None) - request = build_get_node_request( + _request = build_get_node_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_node.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -696,26 +636,22 @@ async def get_node( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = self._deserialize("ServerConfiguration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get_node.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/nodeConfigurations/{configurationName}" - } + return deserialized # type: ignore async def _update_on_node_initial( self, resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: Union[_models.ServerConfiguration, IO], + parameters: Union[_models.ServerConfiguration, IO[bytes]], **kwargs: Any - ) -> _models.ServerConfiguration: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -728,7 +664,7 @@ async def _update_on_node_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.ServerConfiguration] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -738,7 +674,7 @@ async def _update_on_node_initial( else: _json = self._serialize.body(parameters, "ServerConfiguration") - request = build_update_on_node_request( + _request = build_update_on_node_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_name, @@ -747,46 +683,42 @@ async def _update_on_node_initial( content_type=content_type, json=_json, content=_content, - template_url=self._update_on_node_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("ServerConfiguration", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _update_on_node_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/nodeConfigurations/{configurationName}" - } - @overload async def begin_update_on_node( self, @@ -812,14 +744,6 @@ async def begin_update_on_node( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A 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 ServerConfiguration or the result of cls(response) :rtype: @@ -833,7 +757,7 @@ async def begin_update_on_node( resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -848,18 +772,10 @@ async def begin_update_on_node( :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str :param parameters: The required parameters for updating a cluster configuration. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either ServerConfiguration or the result of cls(response) :rtype: @@ -873,7 +789,7 @@ async def begin_update_on_node( resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: Union[_models.ServerConfiguration, IO], + parameters: Union[_models.ServerConfiguration, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.ServerConfiguration]: """Updates configuration of worker nodes in a cluster. @@ -886,19 +802,8 @@ async def begin_update_on_node( :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str :param parameters: The required parameters for updating a cluster configuration. Is either a - ServerConfiguration type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + ServerConfiguration type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration or IO[bytes] :return: An instance of AsyncLROPoller that returns either ServerConfiguration or the result of cls(response) :rtype: @@ -927,12 +832,13 @@ async def begin_update_on_node( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = self._deserialize("ServerConfiguration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -945,14 +851,12 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.ServerConfiguration].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) # type: ignore - - begin_update_on_node.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/nodeConfigurations/{configurationName}" - } + return AsyncLROPoller[_models.ServerConfiguration]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_firewall_rules_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_firewall_rules_operations.py index 956b4aa124c7..b47ae5c67d59 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_firewall_rules_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_firewall_rules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._firewall_rules_operations import ( build_create_or_update_request, build_delete_request, @@ -38,6 +39,10 @@ build_list_by_cluster_request, ) +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -66,10 +71,10 @@ async def _create_or_update_initial( resource_group_name: str, cluster_name: str, firewall_rule_name: str, - parameters: Union[_models.FirewallRule, IO], + parameters: Union[_models.FirewallRule, IO[bytes]], **kwargs: Any - ) -> _models.FirewallRule: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -82,7 +87,7 @@ async def _create_or_update_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.FirewallRule] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -92,7 +97,7 @@ async def _create_or_update_initial( else: _json = self._serialize.body(parameters, "FirewallRule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, cluster_name=cluster_name, firewall_rule_name=firewall_rule_name, @@ -101,46 +106,42 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("FirewallRule", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("FirewallRule", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _create_or_update_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } - @overload async def begin_create_or_update( self, @@ -166,14 +167,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either FirewallRule or the result of cls(response) :rtype: @@ -187,7 +180,7 @@ async def begin_create_or_update( resource_group_name: str, cluster_name: str, firewall_rule_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -202,18 +195,10 @@ async def begin_create_or_update( :param firewall_rule_name: The name of the cluster firewall rule. Required. :type firewall_rule_name: str :param parameters: The required parameters for creating or updating a firewall rule. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either FirewallRule or the result of cls(response) :rtype: @@ -227,7 +212,7 @@ async def begin_create_or_update( resource_group_name: str, cluster_name: str, firewall_rule_name: str, - parameters: Union[_models.FirewallRule, IO], + parameters: Union[_models.FirewallRule, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.FirewallRule]: """Creates a new cluster firewall rule or updates an existing cluster firewall rule. @@ -240,19 +225,8 @@ async def begin_create_or_update( :param firewall_rule_name: The name of the cluster firewall rule. Required. :type firewall_rule_name: str :param parameters: The required parameters for creating or updating a firewall rule. Is either - a FirewallRule type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.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 - :keyword str continuation_token: A 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. + a FirewallRule type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.FirewallRule or IO[bytes] :return: An instance of AsyncLROPoller that returns either FirewallRule or the result of cls(response) :rtype: @@ -281,12 +255,13 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("FirewallRule", pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -299,22 +274,20 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.FirewallRule].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) # type: ignore - - begin_create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } + return AsyncLROPoller[_models.FirewallRule]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, cluster_name: str, firewall_rule_name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -326,29 +299,32 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, cluster_name=cluster_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -360,12 +336,12 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _delete_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -380,14 +356,6 @@ async def begin_delete( :type cluster_name: str :param firewall_rule_name: The name of the cluster firewall rule. Required. :type firewall_rule_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -401,7 +369,7 @@ async def begin_delete( lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, firewall_rule_name=firewall_rule_name, @@ -411,11 +379,12 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: AsyncPollingMethod = cast( @@ -426,17 +395,13 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_delete.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def get( @@ -451,12 +416,11 @@ async def get( :type cluster_name: str :param firewall_rule_name: The name of the cluster firewall rule. Required. :type firewall_rule_name: 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.cosmosdbforpostgresql.models.FirewallRule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -470,22 +434,20 @@ async def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.FirewallRule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, firewall_rule_name=firewall_rule_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -495,16 +457,12 @@ async def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("FirewallRule", pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } + return deserialized # type: ignore @distributed_trace def list_by_cluster( @@ -517,7 +475,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either FirewallRule or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.FirewallRule] @@ -529,7 +486,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.FirewallRuleListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -540,17 +497,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -562,13 +517,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("FirewallRuleListResult", pipeline_response) @@ -578,11 +532,11 @@ async def extract_data(pipeline_response): return None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -594,7 +548,3 @@ async def get_next(next_link=None): return pipeline_response return AsyncItemPaged(get_next, extract_data) - - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules" - } diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_operations.py index c19f6d447c8f..0d0ff85775c0 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,7 +6,8 @@ # 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 +import sys +from typing import Any, AsyncIterable, Callable, Dict, Optional, Type, TypeVar import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -19,16 +20,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._operations import build_list_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -56,7 +59,6 @@ def __init__(self, *args, **kwargs) -> None: def list(self, **kwargs: Any) -> AsyncIterable["_models.Operation"]: """Lists all of the available REST API operations. - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Operation or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Operation] @@ -68,7 +70,7 @@ def list(self, **kwargs: Any) -> AsyncIterable["_models.Operation"]: api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.OperationListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -79,14 +81,12 @@ def list(self, **kwargs: Any) -> AsyncIterable["_models.Operation"]: def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -98,13 +98,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("OperationListResult", pipeline_response) @@ -114,11 +113,11 @@ async def extract_data(pipeline_response): return None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -130,5 +129,3 @@ async def get_next(next_link=None): return pipeline_response return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/providers/Microsoft.DBforPostgreSQL/operations"} diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_private_endpoint_connections_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_private_endpoint_connections_operations.py index 4730b40cf302..e0abc779a82a 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_private_endpoint_connections_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_private_endpoint_connections_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._private_endpoint_connections_operations import ( build_create_or_update_request, build_delete_request, @@ -38,6 +39,10 @@ build_list_by_cluster_request, ) +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -72,7 +77,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either PrivateEndpointConnection or the result of cls(response) :rtype: @@ -85,7 +89,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.PrivateEndpointConnectionListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -96,17 +100,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -118,13 +120,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("PrivateEndpointConnectionListResult", pipeline_response) @@ -134,11 +135,11 @@ async def extract_data(pipeline_response): return None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -151,10 +152,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections" - } - @distributed_trace_async async def get( self, resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, **kwargs: Any @@ -169,12 +166,11 @@ async def get( :param private_endpoint_connection_name: The name of the private endpoint connection associated with the cluster. Required. :type private_endpoint_connection_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: PrivateEndpointConnection or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.PrivateEndpointConnection :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -188,22 +184,20 @@ async def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.PrivateEndpointConnection] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_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"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -213,26 +207,22 @@ async def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } + return deserialized # type: ignore async def _create_or_update_initial( self, resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, - parameters: Union[_models.PrivateEndpointConnection, IO], + parameters: Union[_models.PrivateEndpointConnection, IO[bytes]], **kwargs: Any - ) -> _models.PrivateEndpointConnection: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -245,7 +235,7 @@ async def _create_or_update_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PrivateEndpointConnection] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -255,7 +245,7 @@ async def _create_or_update_initial( else: _json = self._serialize.body(parameters, "PrivateEndpointConnection") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, cluster_name=cluster_name, private_endpoint_connection_name=private_endpoint_connection_name, @@ -264,46 +254,42 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _create_or_update_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } - @overload async def begin_create_or_update( self, @@ -331,14 +317,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either PrivateEndpointConnection or the result of cls(response) :rtype: @@ -352,7 +330,7 @@ async def begin_create_or_update( resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -369,18 +347,10 @@ async def begin_create_or_update( :type private_endpoint_connection_name: str :param parameters: The required parameters for approving a private endpoint connection. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either PrivateEndpointConnection or the result of cls(response) :rtype: @@ -394,7 +364,7 @@ async def begin_create_or_update( resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, - parameters: Union[_models.PrivateEndpointConnection, IO], + parameters: Union[_models.PrivateEndpointConnection, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.PrivateEndpointConnection]: """Approves or Rejects a private endpoint connection with a given name. @@ -408,19 +378,9 @@ async def begin_create_or_update( with the cluster. Required. :type private_endpoint_connection_name: str :param parameters: The required parameters for approving a private endpoint connection. Is - either a PrivateEndpointConnection type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.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. + either a PrivateEndpointConnection type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.PrivateEndpointConnection or + IO[bytes] :return: An instance of AsyncLROPoller that returns either PrivateEndpointConnection or the result of cls(response) :rtype: @@ -449,12 +409,13 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -467,22 +428,20 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.PrivateEndpointConnection].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) # type: ignore - - begin_create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } + return AsyncLROPoller[_models.PrivateEndpointConnection]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -494,29 +453,32 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, cluster_name=cluster_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"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -528,12 +490,12 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _delete_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -549,14 +511,6 @@ async def begin_delete( :param private_endpoint_connection_name: The name of the private endpoint connection associated with the cluster. Required. :type private_endpoint_connection_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -570,7 +524,7 @@ async def begin_delete( lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, private_endpoint_connection_name=private_endpoint_connection_name, @@ -580,11 +534,12 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: AsyncPollingMethod = cast( @@ -595,14 +550,10 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_delete.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_private_link_resources_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_private_link_resources_operations.py index 4f0310bf11f8..57f1b331ddf4 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_private_link_resources_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_private_link_resources_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,7 +6,8 @@ # 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 +import sys +from typing import Any, AsyncIterable, Callable, Dict, Optional, Type, TypeVar import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -19,17 +20,19 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._private_link_resources_operations import build_get_request, build_list_by_cluster_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -64,7 +67,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either PrivateLinkResource or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.PrivateLinkResource] @@ -76,7 +78,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.PrivateLinkResourceListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -87,17 +89,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -109,13 +109,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("PrivateLinkResourceListResult", pipeline_response) @@ -125,11 +124,11 @@ async def extract_data(pipeline_response): return None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -142,10 +141,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateLinkResources" - } - @distributed_trace_async async def get( self, resource_group_name: str, cluster_name: str, private_link_resource_name: str, **kwargs: Any @@ -159,12 +154,11 @@ async def get( :type cluster_name: str :param private_link_resource_name: The name of the private link resource. Required. :type private_link_resource_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: PrivateLinkResource or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.PrivateLinkResource :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -178,22 +172,20 @@ async def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.PrivateLinkResource] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, private_link_resource_name=private_link_resource_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -203,13 +195,9 @@ async def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("PrivateLinkResource", pipeline_response) + deserialized = self._deserialize("PrivateLinkResource", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateLinkResources/{privateLinkResourceName}" - } + return deserialized # type: ignore diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_roles_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_roles_operations.py index 9b338b5f1d85..fe37a0ac6e93 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_roles_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_roles_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._roles_operations import ( build_create_request, build_delete_request, @@ -38,6 +39,10 @@ build_list_by_cluster_request, ) +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -72,12 +77,11 @@ async def get(self, resource_group_name: str, cluster_name: str, role_name: str, :type cluster_name: str :param role_name: The name of the cluster role. Required. :type role_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Role or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.Role :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -91,22 +95,20 @@ async def get(self, resource_group_name: str, cluster_name: str, role_name: str, api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.Role] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, role_name=role_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -116,26 +118,22 @@ async def get(self, resource_group_name: str, cluster_name: str, role_name: str, error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("Role", pipeline_response) + deserialized = self._deserialize("Role", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } + return deserialized # type: ignore async def _create_initial( self, resource_group_name: str, cluster_name: str, role_name: str, - parameters: Union[_models.Role, IO], + parameters: Union[_models.Role, IO[bytes]], **kwargs: Any - ) -> _models.Role: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -148,7 +146,7 @@ async def _create_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Role] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -158,7 +156,7 @@ async def _create_initial( else: _json = self._serialize.body(parameters, "Role") - request = build_create_request( + _request = build_create_request( resource_group_name=resource_group_name, cluster_name=cluster_name, role_name=role_name, @@ -167,46 +165,42 @@ async def _create_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("Role", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("Role", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _create_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } - @overload async def begin_create( self, @@ -232,14 +226,6 @@ async def begin_create( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A 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 Role or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Role] :raises ~azure.core.exceptions.HttpResponseError: @@ -251,7 +237,7 @@ async def begin_create( resource_group_name: str, cluster_name: str, role_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -266,18 +252,10 @@ async def begin_create( :param role_name: The name of the cluster role. Required. :type role_name: str :param parameters: The required parameters for creating or updating a role. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Role or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Role] :raises ~azure.core.exceptions.HttpResponseError: @@ -289,7 +267,7 @@ async def begin_create( resource_group_name: str, cluster_name: str, role_name: str, - parameters: Union[_models.Role, IO], + parameters: Union[_models.Role, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.Role]: """Creates a new role or updates an existing role. @@ -302,19 +280,8 @@ async def begin_create( :param role_name: The name of the cluster role. Required. :type role_name: str :param parameters: The required parameters for creating or updating a role. Is either a Role - type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.Role or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.Role or IO[bytes] :return: An instance of AsyncLROPoller that returns either Role or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Role] :raises ~azure.core.exceptions.HttpResponseError: @@ -341,12 +308,13 @@ async def begin_create( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Role", pipeline_response) + deserialized = self._deserialize("Role", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -359,22 +327,20 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.Role].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) # type: ignore - - begin_create.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } + return AsyncLROPoller[_models.Role]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, cluster_name: str, role_name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -386,29 +352,32 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, cluster_name=cluster_name, role_name=role_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -420,12 +389,12 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _delete_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -440,14 +409,6 @@ async def begin_delete( :type cluster_name: str :param role_name: The name of the cluster role. Required. :type role_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -461,7 +422,7 @@ async def begin_delete( lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, role_name=role_name, @@ -471,11 +432,12 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: AsyncPollingMethod = cast( @@ -486,17 +448,13 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_delete.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def list_by_cluster( @@ -509,7 +467,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Role or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Role] :raises ~azure.core.exceptions.HttpResponseError: @@ -520,7 +477,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.RoleListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -531,17 +488,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -553,13 +508,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("RoleListResult", pipeline_response) @@ -569,11 +523,11 @@ async def extract_data(pipeline_response): return None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -585,7 +539,3 @@ async def get_next(next_link=None): return pipeline_response return AsyncItemPaged(get_next, extract_data) - - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles" - } diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_servers_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_servers_operations.py index b5892b6f66de..e0940d1daec0 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_servers_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/aio/operations/_servers_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,7 +6,8 @@ # 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 +import sys +from typing import Any, AsyncIterable, Callable, Dict, Optional, Type, TypeVar import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -19,17 +20,19 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._servers_operations import build_get_request, build_list_by_cluster_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -64,7 +67,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ClusterServer or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.ClusterServer] @@ -76,7 +78,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterServerListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -87,17 +89,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -109,13 +109,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ClusterServerListResult", pipeline_response) @@ -125,11 +124,11 @@ async def extract_data(pipeline_response): return None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -142,10 +141,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers" - } - @distributed_trace_async async def get( self, resource_group_name: str, cluster_name: str, server_name: str, **kwargs: Any @@ -159,12 +154,11 @@ async def get( :type cluster_name: str :param server_name: The name of the server. Required. :type server_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ClusterServer or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.ClusterServer :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -178,22 +172,20 @@ async def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterServer] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, server_name=server_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -203,13 +195,9 @@ async def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("ClusterServer", pipeline_response) + deserialized = self._deserialize("ClusterServer", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers/{serverName}" - } + return deserialized # type: ignore diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/__init__.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/__init__.py index 7a5e58e65419..f8d92a2cfa79 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/__init__.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/__init__.py @@ -15,11 +15,13 @@ from ._models_py3 import ClusterServerListResult from ._models_py3 import ClusterServerProperties from ._models_py3 import Configuration +from ._models_py3 import DataEncryption from ._models_py3 import ErrorAdditionalInfo from ._models_py3 import ErrorDetail from ._models_py3 import ErrorResponse from ._models_py3 import FirewallRule from ._models_py3 import FirewallRuleListResult +from ._models_py3 import IdentityProperties from ._models_py3 import MaintenanceWindow from ._models_py3 import NameAvailability from ._models_py3 import NameAvailabilityRequest @@ -46,12 +48,17 @@ from ._models_py3 import SimplePrivateEndpointConnection from ._models_py3 import SystemData from ._models_py3 import TrackedResource +from ._models_py3 import UserAssignedIdentity +from ._cosmosdb_for_postgresql_mgmt_client_enums import AadEnabledEnum from ._cosmosdb_for_postgresql_mgmt_client_enums import ActiveDirectoryAuth from ._cosmosdb_for_postgresql_mgmt_client_enums import ConfigurationDataType from ._cosmosdb_for_postgresql_mgmt_client_enums import CreatedByType +from ._cosmosdb_for_postgresql_mgmt_client_enums import DataEncryptionType +from ._cosmosdb_for_postgresql_mgmt_client_enums import IdentityType from ._cosmosdb_for_postgresql_mgmt_client_enums import OperationOrigin from ._cosmosdb_for_postgresql_mgmt_client_enums import PasswordAuth +from ._cosmosdb_for_postgresql_mgmt_client_enums import PasswordEnabledEnum from ._cosmosdb_for_postgresql_mgmt_client_enums import PrincipalType from ._cosmosdb_for_postgresql_mgmt_client_enums import PrivateEndpointConnectionProvisioningState from ._cosmosdb_for_postgresql_mgmt_client_enums import PrivateEndpointServiceConnectionStatus @@ -72,11 +79,13 @@ "ClusterServerListResult", "ClusterServerProperties", "Configuration", + "DataEncryption", "ErrorAdditionalInfo", "ErrorDetail", "ErrorResponse", "FirewallRule", "FirewallRuleListResult", + "IdentityProperties", "MaintenanceWindow", "NameAvailability", "NameAvailabilityRequest", @@ -103,11 +112,16 @@ "SimplePrivateEndpointConnection", "SystemData", "TrackedResource", + "UserAssignedIdentity", + "AadEnabledEnum", "ActiveDirectoryAuth", "ConfigurationDataType", "CreatedByType", + "DataEncryptionType", + "IdentityType", "OperationOrigin", "PasswordAuth", + "PasswordEnabledEnum", "PrincipalType", "PrivateEndpointConnectionProvisioningState", "PrivateEndpointServiceConnectionStatus", diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/_cosmosdb_for_postgresql_mgmt_client_enums.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/_cosmosdb_for_postgresql_mgmt_client_enums.py index 5cf91505bf40..3bd85b2619d1 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/_cosmosdb_for_postgresql_mgmt_client_enums.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/_cosmosdb_for_postgresql_mgmt_client_enums.py @@ -10,6 +10,13 @@ from azure.core import CaseInsensitiveEnumMeta +class AadEnabledEnum(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """Indicates whether the cluster was created using AAD authentication.""" + + ENABLED = "enabled" + DISABLED = "disabled" + + class ActiveDirectoryAuth(str, Enum, metaclass=CaseInsensitiveEnumMeta): """ActiveDirectoryAuth.""" @@ -35,6 +42,20 @@ class CreatedByType(str, Enum, metaclass=CaseInsensitiveEnumMeta): KEY = "Key" +class DataEncryptionType(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """DataEncryptionType.""" + + AZURE_KEY_VAULT = "AzureKeyVault" + SYSTEM_ASSIGNED = "SystemAssigned" + + +class IdentityType(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """IdentityType.""" + + USER_ASSIGNED = "UserAssigned" + SYSTEM_ASSIGNED = "SystemAssigned" + + class OperationOrigin(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The intended executor of the operation.""" @@ -50,6 +71,13 @@ class PasswordAuth(str, Enum, metaclass=CaseInsensitiveEnumMeta): DISABLED = "disabled" +class PasswordEnabledEnum(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """Indicates whether the cluster was created with a password or using AAD authentication.""" + + ENABLED = "enabled" + DISABLED = "disabled" + + class PrincipalType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """PrincipalType.""" diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/_models_py3.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/_models_py3.py index b1b24f7eda86..4209fd63b8bb 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/_models_py3.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/models/_models_py3.py @@ -57,7 +57,7 @@ class Resource(_serialization.Model): Variables are only populated by the server, and will be ignored when sending a request. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -98,10 +98,10 @@ class TrackedResource(Resource): 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. + All required parameters must be populated in order to send to server. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -151,10 +151,10 @@ class Cluster(TrackedResource): # pylint: disable=too-many-instance-attributes 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. + All required parameters must be populated in order to send to server. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -168,11 +168,18 @@ class Cluster(TrackedResource): # pylint: disable=too-many-instance-attributes :vartype tags: dict[str, str] :ivar location: The geo-location where the resource lives. Required. :vartype location: str + :ivar identity: Describes the identity of the cluster. + :vartype identity: ~azure.mgmt.cosmosdbforpostgresql.models.IdentityProperties + :ivar aad_auth_enabled: Indicates whether the cluster was created using AAD authentication. + Known values are: "enabled" and "disabled". + :vartype aad_auth_enabled: str or ~azure.mgmt.cosmosdbforpostgresql.models.AadEnabledEnum :ivar administrator_login: The administrator's login name of the servers in the cluster. :vartype administrator_login: str :ivar administrator_login_password: The password of the administrator login. Required for creation. :vartype administrator_login_password: str + :ivar data_encryption: The data encryption properties of a cluster. + :vartype data_encryption: ~azure.mgmt.cosmosdbforpostgresql.models.DataEncryption :ivar provisioning_state: Provisioning state of the cluster. :vartype provisioning_state: str :ivar state: A state of a cluster/server that is visible to user. @@ -224,6 +231,9 @@ class Cluster(TrackedResource): # pylint: disable=too-many-instance-attributes :vartype source_resource_id: str :ivar source_location: The Azure region of source cluster for read replica clusters. :vartype source_location: str + :ivar password_enabled: Indicates whether the cluster was created with a password or using AAD + authentication. Known values are: "enabled" and "disabled". + :vartype password_enabled: str or ~azure.mgmt.cosmosdbforpostgresql.models.PasswordEnabledEnum :ivar point_in_time_utc: Date and time in UTC (ISO8601 format) for cluster restore. :vartype point_in_time_utc: ~datetime.datetime :ivar read_replicas: The array of read replica clusters. @@ -250,10 +260,12 @@ class Cluster(TrackedResource): # pylint: disable=too-many-instance-attributes "type": {"readonly": True}, "system_data": {"readonly": True}, "location": {"required": True}, + "aad_auth_enabled": {"readonly": True}, "administrator_login": {"readonly": True}, "provisioning_state": {"readonly": True}, "state": {"readonly": True}, "server_names": {"readonly": True, "unique": True}, + "password_enabled": {"readonly": True}, "read_replicas": {"readonly": True, "unique": True}, "earliest_restore_time": {"readonly": True}, "private_endpoint_connections": {"readonly": True}, @@ -266,8 +278,11 @@ class Cluster(TrackedResource): # pylint: disable=too-many-instance-attributes "system_data": {"key": "systemData", "type": "SystemData"}, "tags": {"key": "tags", "type": "{str}"}, "location": {"key": "location", "type": "str"}, + "identity": {"key": "identity", "type": "IdentityProperties"}, + "aad_auth_enabled": {"key": "properties.aadAuthEnabled", "type": "str"}, "administrator_login": {"key": "properties.administratorLogin", "type": "str"}, "administrator_login_password": {"key": "properties.administratorLoginPassword", "type": "str"}, + "data_encryption": {"key": "properties.dataEncryption", "type": "DataEncryption"}, "provisioning_state": {"key": "properties.provisioningState", "type": "str"}, "state": {"key": "properties.state", "type": "str"}, "postgresql_version": {"key": "properties.postgresqlVersion", "type": "str"}, @@ -288,6 +303,7 @@ class Cluster(TrackedResource): # pylint: disable=too-many-instance-attributes "server_names": {"key": "properties.serverNames", "type": "[ServerNameItem]"}, "source_resource_id": {"key": "properties.sourceResourceId", "type": "str"}, "source_location": {"key": "properties.sourceLocation", "type": "str"}, + "password_enabled": {"key": "properties.passwordEnabled", "type": "str"}, "point_in_time_utc": {"key": "properties.pointInTimeUTC", "type": "iso-8601"}, "read_replicas": {"key": "properties.readReplicas", "type": "[str]"}, "earliest_restore_time": {"key": "properties.earliestRestoreTime", "type": "iso-8601"}, @@ -305,7 +321,9 @@ def __init__( # pylint: disable=too-many-locals *, location: str, tags: Optional[Dict[str, str]] = None, + identity: Optional["_models.IdentityProperties"] = None, administrator_login_password: Optional[str] = None, + data_encryption: Optional["_models.DataEncryption"] = None, postgresql_version: Optional[str] = None, citus_version: Optional[str] = None, maintenance_window: Optional["_models.MaintenanceWindow"] = None, @@ -334,9 +352,13 @@ def __init__( # pylint: disable=too-many-locals :paramtype tags: dict[str, str] :keyword location: The geo-location where the resource lives. Required. :paramtype location: str + :keyword identity: Describes the identity of the cluster. + :paramtype identity: ~azure.mgmt.cosmosdbforpostgresql.models.IdentityProperties :keyword administrator_login_password: The password of the administrator login. Required for creation. :paramtype administrator_login_password: str + :keyword data_encryption: The data encryption properties of a cluster. + :paramtype data_encryption: ~azure.mgmt.cosmosdbforpostgresql.models.DataEncryption :keyword postgresql_version: The major PostgreSQL version on all cluster servers. :paramtype postgresql_version: str :keyword citus_version: The Citus extension version on all cluster servers. @@ -397,8 +419,11 @@ def __init__( # pylint: disable=too-many-locals :paramtype auth_config: ~azure.mgmt.cosmosdbforpostgresql.models.AuthConfig """ super().__init__(tags=tags, location=location, **kwargs) + self.identity = identity + self.aad_auth_enabled = None self.administrator_login = None self.administrator_login_password = administrator_login_password + self.data_encryption = data_encryption self.provisioning_state = None self.state = None self.postgresql_version = postgresql_version @@ -419,6 +444,7 @@ def __init__( # pylint: disable=too-many-locals self.server_names = None self.source_resource_id = source_resource_id self.source_location = source_location + self.password_enabled = None self.point_in_time_utc = point_in_time_utc self.read_replicas = None self.earliest_restore_time = None @@ -463,6 +489,8 @@ class ClusterForUpdate(_serialization.Model): # pylint: disable=too-many-instan Variables are only populated by the server, and will be ignored when sending a request. + :ivar identity: Describes the identity of the cluster. + :vartype identity: ~azure.mgmt.cosmosdbforpostgresql.models.IdentityProperties :ivar tags: Application-specific metadata in the form of key-value pairs. :vartype tags: dict[str, str] :ivar administrator_login_password: The password of the administrator login. Each cluster is @@ -509,6 +537,7 @@ class ClusterForUpdate(_serialization.Model): # pylint: disable=too-many-instan } _attribute_map = { + "identity": {"key": "identity", "type": "IdentityProperties"}, "tags": {"key": "tags", "type": "{str}"}, "administrator_login_password": {"key": "properties.administratorLoginPassword", "type": "str"}, "postgresql_version": {"key": "properties.postgresqlVersion", "type": "str"}, @@ -531,6 +560,7 @@ class ClusterForUpdate(_serialization.Model): # pylint: disable=too-many-instan def __init__( self, *, + identity: Optional["_models.IdentityProperties"] = None, tags: Optional[Dict[str, str]] = None, administrator_login_password: Optional[str] = None, postgresql_version: Optional[str] = None, @@ -550,6 +580,8 @@ def __init__( **kwargs: Any ) -> None: """ + :keyword identity: Describes the identity of the cluster. + :paramtype identity: ~azure.mgmt.cosmosdbforpostgresql.models.IdentityProperties :keyword tags: Application-specific metadata in the form of key-value pairs. :paramtype tags: dict[str, str] :keyword administrator_login_password: The password of the administrator login. Each cluster is @@ -590,6 +622,7 @@ def __init__( :paramtype maintenance_window: ~azure.mgmt.cosmosdbforpostgresql.models.MaintenanceWindow """ super().__init__(**kwargs) + self.identity = identity self.tags = tags self.administrator_login_password = administrator_login_password self.postgresql_version = postgresql_version @@ -646,7 +679,7 @@ class ProxyResource(Resource): Variables are only populated by the server, and will be ignored when sending a request. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -658,24 +691,6 @@ class ProxyResource(Resource): :vartype system_data: ~azure.mgmt.cosmosdbforpostgresql.models.SystemData """ - _validation = { - "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"}, - } - - def __init__(self, **kwargs: Any) -> None: - """ """ - super().__init__(**kwargs) - class ClusterServer(ProxyResource): # pylint: disable=too-many-instance-attributes """Represents a server in a cluster. @@ -683,7 +698,7 @@ class ClusterServer(ProxyResource): # pylint: disable=too-many-instance-attribu Variables are only populated by the server, and will be ignored when sending a request. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -1008,7 +1023,7 @@ class Configuration(ProxyResource): Variables are only populated by the server, and will be ignored when sending a request. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -1086,6 +1101,48 @@ def __init__( self.provisioning_state = None +class DataEncryption(_serialization.Model): + """The data encryption properties of a cluster. + + :ivar primary_key_uri: URI for the key in keyvault for data encryption of the primary server. + :vartype primary_key_uri: str + :ivar primary_user_assigned_identity_id: Resource Id for the User assigned identity to be used + for data encryption of the primary server. + :vartype primary_user_assigned_identity_id: str + :ivar type: Known values are: "AzureKeyVault" and "SystemAssigned". + :vartype type: str or ~azure.mgmt.cosmosdbforpostgresql.models.DataEncryptionType + """ + + _attribute_map = { + "primary_key_uri": {"key": "primaryKeyUri", "type": "str"}, + "primary_user_assigned_identity_id": {"key": "primaryUserAssignedIdentityId", "type": "str"}, + "type": {"key": "type", "type": "str"}, + } + + def __init__( + self, + *, + primary_key_uri: Optional[str] = None, + primary_user_assigned_identity_id: Optional[str] = None, + type: Optional[Union[str, "_models.DataEncryptionType"]] = None, + **kwargs: Any + ) -> None: + """ + :keyword primary_key_uri: URI for the key in keyvault for data encryption of the primary + server. + :paramtype primary_key_uri: str + :keyword primary_user_assigned_identity_id: Resource Id for the User assigned identity to be + used for data encryption of the primary server. + :paramtype primary_user_assigned_identity_id: str + :keyword type: Known values are: "AzureKeyVault" and "SystemAssigned". + :paramtype type: str or ~azure.mgmt.cosmosdbforpostgresql.models.DataEncryptionType + """ + super().__init__(**kwargs) + self.primary_key_uri = primary_key_uri + self.primary_user_assigned_identity_id = primary_user_assigned_identity_id + self.type = type + + class ErrorAdditionalInfo(_serialization.Model): """The resource management error additional info. @@ -1183,10 +1240,10 @@ class FirewallRule(ProxyResource): 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. + All required parameters must be populated in order to send to server. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -1268,6 +1325,46 @@ def __init__(self, *, value: Optional[List["_models.FirewallRule"]] = None, **kw self.value = value +class IdentityProperties(_serialization.Model): + """Describes the identity of the cluster. + + :ivar type: Known values are: "UserAssigned" and "SystemAssigned". + :vartype type: str or ~azure.mgmt.cosmosdbforpostgresql.models.IdentityType + :ivar user_assigned_identities: The set of user assigned identities associated with the + resource. The userAssignedIdentities dictionary keys will be ARM resource ids in the form: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. # pylint: disable=line-too-long + The dictionary values can be empty objects ({}) in requests. + :vartype user_assigned_identities: dict[str, + ~azure.mgmt.cosmosdbforpostgresql.models.UserAssignedIdentity] + """ + + _attribute_map = { + "type": {"key": "type", "type": "str"}, + "user_assigned_identities": {"key": "userAssignedIdentities", "type": "{UserAssignedIdentity}"}, + } + + def __init__( + self, + *, + type: Optional[Union[str, "_models.IdentityType"]] = None, + user_assigned_identities: Optional[Dict[str, "_models.UserAssignedIdentity"]] = None, + **kwargs: Any + ) -> None: + """ + :keyword type: Known values are: "UserAssigned" and "SystemAssigned". + :paramtype type: str or ~azure.mgmt.cosmosdbforpostgresql.models.IdentityType + :keyword user_assigned_identities: The set of user assigned identities associated with the + resource. The userAssignedIdentities dictionary keys will be ARM resource ids in the form: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. # pylint: disable=line-too-long + The dictionary values can be empty objects ({}) in requests. + :paramtype user_assigned_identities: dict[str, + ~azure.mgmt.cosmosdbforpostgresql.models.UserAssignedIdentity] + """ + super().__init__(**kwargs) + self.type = type + self.user_assigned_identities = user_assigned_identities + + class MaintenanceWindow(_serialization.Model): """Schedule settings for regular cluster updates. @@ -1365,7 +1462,7 @@ class NameAvailabilityRequest(_serialization.Model): 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. + All required parameters must be populated in order to send to server. :ivar name: Cluster name to verify. Required. :vartype name: str @@ -1539,7 +1636,7 @@ class PrivateEndpointConnection(Resource): Variables are only populated by the server, and will be ignored when sending a request. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -1654,7 +1751,7 @@ class PrivateLinkResource(Resource): Variables are only populated by the server, and will be ignored when sending a request. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -1771,7 +1868,7 @@ def __init__( class PromoteRequest(_serialization.Model): """Request from client to promote geo-redundant replica. - :ivar enable_geo_backup: Cluster name to verify. + :ivar enable_geo_backup: Boolean property to enable geo-redundant replica promotion. :vartype enable_geo_backup: bool """ @@ -1781,7 +1878,7 @@ class PromoteRequest(_serialization.Model): def __init__(self, *, enable_geo_backup: Optional[bool] = None, **kwargs: Any) -> None: """ - :keyword enable_geo_backup: Cluster name to verify. + :keyword enable_geo_backup: Boolean property to enable geo-redundant replica promotion. :paramtype enable_geo_backup: bool """ super().__init__(**kwargs) @@ -1794,7 +1891,7 @@ class Role(ProxyResource): Variables are only populated by the server, and will be ignored when sending a request. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -1899,7 +1996,7 @@ class ServerConfiguration(ProxyResource): # pylint: disable=too-many-instance-a Variables are only populated by the server, and will be ignored when sending a request. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -2039,7 +2136,7 @@ class ServerRoleGroupConfiguration(_serialization.Model): 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. + All required parameters must be populated in order to send to server. :ivar role: The role of servers in the server role group. Required. Known values are: "Coordinator" and "Worker". @@ -2087,7 +2184,7 @@ class SimplePrivateEndpointConnection(ProxyResource): Variables are only populated by the server, and will be ignored when sending a request. :ivar id: Fully qualified resource ID for the resource. E.g. - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". # pylint: disable=line-too-long :vartype id: str :ivar name: The name of the resource. :vartype name: str @@ -2213,3 +2310,31 @@ def __init__( self.last_modified_by = last_modified_by self.last_modified_by_type = last_modified_by_type self.last_modified_at = last_modified_at + + +class UserAssignedIdentity(_serialization.Model): + """User assigned identity properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar principal_id: The principal ID of the assigned identity. + :vartype principal_id: str + :ivar client_id: The client ID of the assigned identity. + :vartype client_id: str + """ + + _validation = { + "principal_id": {"readonly": True}, + "client_id": {"readonly": True}, + } + + _attribute_map = { + "principal_id": {"key": "principalId", "type": "str"}, + "client_id": {"key": "clientId", "type": "str"}, + } + + def __init__(self, **kwargs: Any) -> None: + """ """ + super().__init__(**kwargs) + self.principal_id = None + self.client_id = None diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_clusters_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_clusters_operations.py index 90764b2c228d..dd35f8284a66 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_clusters_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_clusters_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,8 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -472,7 +477,6 @@ def __init__(self, *args, **kwargs): def list(self, **kwargs: Any) -> Iterable["_models.Cluster"]: """Lists all clusters in a subscription. - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Cluster or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] :raises ~azure.core.exceptions.HttpResponseError: @@ -483,7 +487,7 @@ def list(self, **kwargs: Any) -> Iterable["_models.Cluster"]: api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -494,15 +498,13 @@ def list(self, **kwargs: Any) -> Iterable["_models.Cluster"]: def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -514,13 +516,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ClusterListResult", pipeline_response) @@ -530,11 +531,11 @@ def extract_data(pipeline_response): return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -547,8 +548,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2"} - @distributed_trace def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> Iterable["_models.Cluster"]: """Lists all clusters in a resource group. @@ -556,7 +555,6 @@ def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> Ite :param resource_group_name: The name of the resource group. The name is case insensitive. Required. :type resource_group_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Cluster or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] :raises ~azure.core.exceptions.HttpResponseError: @@ -567,7 +565,7 @@ def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> Ite api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -578,16 +576,14 @@ def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> Ite def prepare_request(next_link=None): if not next_link: - request = build_list_by_resource_group_request( + _request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -599,13 +595,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ClusterListResult", pipeline_response) @@ -615,11 +610,11 @@ def extract_data(pipeline_response): return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -632,14 +627,10 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2" - } - def _create_initial( - self, resource_group_name: str, cluster_name: str, parameters: Union[_models.Cluster, IO], **kwargs: Any - ) -> _models.Cluster: - error_map = { + self, resource_group_name: str, cluster_name: str, parameters: Union[_models.Cluster, IO[bytes]], **kwargs: Any + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -652,7 +643,7 @@ def _create_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Cluster] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -662,7 +653,7 @@ def _create_initial( else: _json = self._serialize.body(parameters, "Cluster") - request = build_create_request( + _request = build_create_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, @@ -670,46 +661,42 @@ def _create_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("Cluster", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _create_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } - @overload def begin_create( self, @@ -732,14 +719,6 @@ def begin_create( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation 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 Cluster or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] :raises ~azure.core.exceptions.HttpResponseError: @@ -750,7 +729,7 @@ def begin_create( self, resource_group_name: str, cluster_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -763,18 +742,10 @@ def begin_create( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param parameters: The required parameters for creating or updating a cluster. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] :raises ~azure.core.exceptions.HttpResponseError: @@ -782,7 +753,7 @@ def begin_create( @distributed_trace def begin_create( - self, resource_group_name: str, cluster_name: str, parameters: Union[_models.Cluster, IO], **kwargs: Any + self, resource_group_name: str, cluster_name: str, parameters: Union[_models.Cluster, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.Cluster]: """Creates a new cluster with servers. @@ -792,19 +763,8 @@ def begin_create( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param parameters: The required parameters for creating or updating a cluster. Is either a - Cluster type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.Cluster or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + Cluster type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.Cluster or IO[bytes] :return: An instance of LROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] :raises ~azure.core.exceptions.HttpResponseError: @@ -830,12 +790,13 @@ def begin_create( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = self._deserialize("Cluster", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -847,17 +808,15 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.Cluster].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) # type: ignore - - begin_create.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return LROPoller[_models.Cluster]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) @distributed_trace def get(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> _models.Cluster: @@ -869,12 +828,11 @@ def get(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> _mo :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Cluster or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.Cluster :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -888,21 +846,19 @@ def get(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> _mo api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.Cluster] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -912,21 +868,15 @@ def get(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> _mo error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = self._deserialize("Cluster", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return deserialized # type: ignore - def _delete_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, cluster_name: str, **kwargs: Any - ) -> None: - error_map = { + def _delete_initial(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -938,28 +888,31 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -971,12 +924,12 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _delete_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return deserialized # type: ignore @distributed_trace def begin_delete(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> LROPoller[None]: @@ -987,14 +940,6 @@ def begin_delete(self, resource_group_name: str, cluster_name: str, **kwargs: An :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1008,7 +953,7 @@ def begin_delete(self, resource_group_name: str, cluster_name: str, **kwargs: An lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, api_version=api_version, @@ -1017,11 +962,12 @@ def begin_delete(self, resource_group_name: str, cluster_name: str, **kwargs: An params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: PollingMethod = cast( @@ -1032,26 +978,22 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_delete.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore def _update_initial( self, resource_group_name: str, cluster_name: str, - parameters: Union[_models.ClusterForUpdate, IO], + parameters: Union[_models.ClusterForUpdate, IO[bytes]], **kwargs: Any - ) -> _models.Cluster: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1064,7 +1006,7 @@ def _update_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Cluster] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -1074,7 +1016,7 @@ def _update_initial( else: _json = self._serialize.body(parameters, "ClusterForUpdate") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, @@ -1082,46 +1024,42 @@ def _update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("Cluster", pipeline_response) - if response.status_code == 202: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _update_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } - @overload def begin_update( self, @@ -1145,14 +1083,6 @@ def begin_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] :raises ~azure.core.exceptions.HttpResponseError: @@ -1163,7 +1093,7 @@ def begin_update( self, resource_group_name: str, cluster_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -1177,18 +1107,10 @@ def begin_update( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param parameters: The parameters for updating a cluster. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] :raises ~azure.core.exceptions.HttpResponseError: @@ -1199,7 +1121,7 @@ def begin_update( self, resource_group_name: str, cluster_name: str, - parameters: Union[_models.ClusterForUpdate, IO], + parameters: Union[_models.ClusterForUpdate, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.Cluster]: """Updates an existing cluster. The request body can contain one or several properties from the @@ -1211,19 +1133,8 @@ def begin_update( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param parameters: The parameters for updating a cluster. Is either a ClusterForUpdate type or - a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ClusterForUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ClusterForUpdate or IO[bytes] :return: An instance of LROPoller that returns either Cluster or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Cluster] :raises ~azure.core.exceptions.HttpResponseError: @@ -1249,12 +1160,13 @@ def begin_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Cluster", pipeline_response) + deserialized = self._deserialize("Cluster", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -1266,22 +1178,18 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.Cluster].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) # type: ignore - - begin_update.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" - } + return LROPoller[_models.Cluster]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _restart_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, cluster_name: str, **kwargs: Any - ) -> None: - error_map = { + def _restart_initial(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1293,28 +1201,31 @@ def _restart_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_restart_request( + _request = build_restart_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._restart_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -1325,12 +1236,12 @@ def _restart_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _restart_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/restart" - } + return deserialized # type: ignore @distributed_trace def begin_restart(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> LROPoller[None]: @@ -1341,14 +1252,6 @@ def begin_restart(self, resource_group_name: str, cluster_name: str, **kwargs: A :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1362,7 +1265,7 @@ def begin_restart(self, resource_group_name: str, cluster_name: str, **kwargs: A lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._restart_initial( # type: ignore + raw_result = self._restart_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, api_version=api_version, @@ -1371,11 +1274,12 @@ def begin_restart(self, resource_group_name: str, cluster_name: str, **kwargs: A params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: PollingMethod = cast( @@ -1386,22 +1290,16 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_restart.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/restart" - } + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _start_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, cluster_name: str, **kwargs: Any - ) -> None: - error_map = { + def _start_initial(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1413,28 +1311,31 @@ def _start_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_start_request( + _request = build_start_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._start_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -1446,12 +1347,12 @@ def _start_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _start_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/start" - } + return deserialized # type: ignore @distributed_trace def begin_start(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> LROPoller[None]: @@ -1462,14 +1363,6 @@ def begin_start(self, resource_group_name: str, cluster_name: str, **kwargs: Any :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1483,7 +1376,7 @@ def begin_start(self, resource_group_name: str, cluster_name: str, **kwargs: Any lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._start_initial( # type: ignore + raw_result = self._start_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, api_version=api_version, @@ -1492,11 +1385,12 @@ def begin_start(self, resource_group_name: str, cluster_name: str, **kwargs: Any params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: PollingMethod = cast( @@ -1507,22 +1401,16 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_start.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/start" - } + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _stop_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, cluster_name: str, **kwargs: Any - ) -> None: - error_map = { + def _stop_initial(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1534,28 +1422,31 @@ def _stop_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_stop_request( + _request = build_stop_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._stop_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -1567,12 +1458,12 @@ def _stop_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _stop_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/stop" - } + return deserialized # type: ignore @distributed_trace def begin_stop(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> LROPoller[None]: @@ -1583,14 +1474,6 @@ def begin_stop(self, resource_group_name: str, cluster_name: str, **kwargs: Any) :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1604,7 +1487,7 @@ def begin_stop(self, resource_group_name: str, cluster_name: str, **kwargs: Any) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._stop_initial( # type: ignore + raw_result = self._stop_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, api_version=api_version, @@ -1613,11 +1496,12 @@ def begin_stop(self, resource_group_name: str, cluster_name: str, **kwargs: Any) params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: PollingMethod = cast( @@ -1628,26 +1512,22 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_stop.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/stop" - } - - def _promote_read_replica_initial( # pylint: disable=inconsistent-return-statements + def _promote_read_replica_initial( self, resource_group_name: str, cluster_name: str, - promote_request: Optional[Union[_models.PromoteRequest, IO]] = None, + promote_request: Optional[Union[_models.PromoteRequest, IO[bytes]]] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1660,7 +1540,7 @@ def _promote_read_replica_initial( # pylint: disable=inconsistent-return-statem api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -1673,7 +1553,7 @@ def _promote_read_replica_initial( # pylint: disable=inconsistent-return-statem else: _json = None - request = build_promote_read_replica_request( + _request = build_promote_read_replica_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, @@ -1681,21 +1561,24 @@ def _promote_read_replica_initial( # pylint: disable=inconsistent-return-statem content_type=content_type, json=_json, content=_content, - template_url=self._promote_read_replica_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -1706,12 +1589,12 @@ def _promote_read_replica_initial( # pylint: disable=inconsistent-return-statem "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _promote_read_replica_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/promote" - } + return deserialized # type: ignore @overload def begin_promote_read_replica( @@ -1736,14 +1619,6 @@ def begin_promote_read_replica( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation 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: @@ -1754,7 +1629,7 @@ def begin_promote_read_replica( self, resource_group_name: str, cluster_name: str, - promote_request: Optional[IO] = None, + promote_request: Optional[IO[bytes]] = None, *, content_type: str = "application/json", **kwargs: Any @@ -1768,18 +1643,10 @@ def begin_promote_read_replica( :type cluster_name: str :param promote_request: The parameter for enabling geo-redundant backup while promoting read replica. Default value is None. - :type promote_request: IO + :type promote_request: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation 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: @@ -1790,7 +1657,7 @@ def begin_promote_read_replica( self, resource_group_name: str, cluster_name: str, - promote_request: Optional[Union[_models.PromoteRequest, IO]] = None, + promote_request: Optional[Union[_models.PromoteRequest, IO[bytes]]] = None, **kwargs: Any ) -> LROPoller[None]: """Promotes read replica cluster to an independent read-write cluster. @@ -1801,19 +1668,8 @@ def begin_promote_read_replica( :param cluster_name: The name of the cluster. Required. :type cluster_name: str :param promote_request: The parameter for enabling geo-redundant backup while promoting read - replica. Is either a PromoteRequest type or a IO type. Default value is None. - :type promote_request: ~azure.mgmt.cosmosdbforpostgresql.models.PromoteRequest or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + replica. Is either a PromoteRequest type or a IO[bytes] type. Default value is None. + :type promote_request: ~azure.mgmt.cosmosdbforpostgresql.models.PromoteRequest or IO[bytes] :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1828,7 +1684,7 @@ def begin_promote_read_replica( lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._promote_read_replica_initial( # type: ignore + raw_result = self._promote_read_replica_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, promote_request=promote_request, @@ -1839,11 +1695,12 @@ def begin_promote_read_replica( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: PollingMethod = cast( @@ -1854,17 +1711,13 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_promote_read_replica.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/promote" - } + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @overload def check_name_availability( @@ -1885,7 +1738,6 @@ def check_name_availability( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. 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: NameAvailability or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailability :raises ~azure.core.exceptions.HttpResponseError: @@ -1893,7 +1745,7 @@ def check_name_availability( @overload def check_name_availability( - self, name_availability_request: IO, *, content_type: str = "application/json", **kwargs: Any + self, name_availability_request: IO[bytes], *, content_type: str = "application/json", **kwargs: Any ) -> _models.NameAvailability: """Checks availability of a cluster name. Cluster names should be globally unique; at least 3 characters and at most 40 characters long; they must only contain lowercase letters, numbers, @@ -1901,11 +1753,10 @@ def check_name_availability( :param name_availability_request: The required parameters for checking if cluster name is available. Required. - :type name_availability_request: IO + :type name_availability_request: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: NameAvailability or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailability :raises ~azure.core.exceptions.HttpResponseError: @@ -1913,25 +1764,21 @@ def check_name_availability( @distributed_trace def check_name_availability( - self, name_availability_request: Union[_models.NameAvailabilityRequest, IO], **kwargs: Any + self, name_availability_request: Union[_models.NameAvailabilityRequest, IO[bytes]], **kwargs: Any ) -> _models.NameAvailability: """Checks availability of a cluster name. Cluster names should be globally unique; at least 3 characters and at most 40 characters long; they must only contain lowercase letters, numbers, and hyphens; and must not start or end with a hyphen. :param name_availability_request: The required parameters for checking if cluster name is - available. Is either a NameAvailabilityRequest type or a IO type. Required. + available. Is either a NameAvailabilityRequest type or a IO[bytes] type. Required. :type name_availability_request: - ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailabilityRequest or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailabilityRequest or IO[bytes] :return: NameAvailability or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.NameAvailability :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1954,22 +1801,20 @@ def check_name_availability( else: _json = self._serialize.body(name_availability_request, "NameAvailabilityRequest") - request = build_check_name_availability_request( + _request = build_check_name_availability_request( subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, content=_content, - template_url=self.check_name_availability.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1979,13 +1824,9 @@ def check_name_availability( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("NameAvailability", pipeline_response) + deserialized = self._deserialize("NameAvailability", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - check_name_availability.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/checkNameAvailability" - } + return deserialized # type: ignore diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_configurations_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_configurations_operations.py index dd560a796f50..c6a19f7886f9 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_configurations_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_configurations_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,8 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -375,7 +380,6 @@ def list_by_server( :type cluster_name: str :param server_name: The name of the server. Required. :type server_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ServerConfiguration or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration] @@ -387,7 +391,7 @@ def list_by_server( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ServerConfigurationListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -398,18 +402,16 @@ def list_by_server( def prepare_request(next_link=None): if not next_link: - request = build_list_by_server_request( + _request = build_list_by_server_request( resource_group_name=resource_group_name, cluster_name=cluster_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -421,13 +423,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ServerConfigurationListResult", pipeline_response) @@ -437,11 +438,11 @@ def extract_data(pipeline_response): return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -454,10 +455,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_server.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers/{serverName}/configurations" - } - @distributed_trace def list_by_cluster( self, resource_group_name: str, cluster_name: str, **kwargs: Any @@ -469,7 +466,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Configuration or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Configuration] :raises ~azure.core.exceptions.HttpResponseError: @@ -480,7 +476,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterConfigurationListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -491,17 +487,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -513,13 +507,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ClusterConfigurationListResult", pipeline_response) @@ -529,11 +522,11 @@ def extract_data(pipeline_response): return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -546,10 +539,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/configurations" - } - @distributed_trace def get( self, resource_group_name: str, cluster_name: str, configuration_name: str, **kwargs: Any @@ -563,12 +552,11 @@ def get( :type cluster_name: str :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Configuration or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.Configuration :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -582,22 +570,20 @@ def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.Configuration] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -607,16 +593,12 @@ def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("Configuration", pipeline_response) + deserialized = self._deserialize("Configuration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/configurations/{configurationName}" - } + return deserialized # type: ignore @distributed_trace def get_coordinator( @@ -631,12 +613,11 @@ def get_coordinator( :type cluster_name: str :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServerConfiguration or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -650,22 +631,20 @@ def get_coordinator( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ServerConfiguration] = kwargs.pop("cls", None) - request = build_get_coordinator_request( + _request = build_get_coordinator_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_coordinator.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -675,26 +654,22 @@ def get_coordinator( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = self._deserialize("ServerConfiguration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get_coordinator.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/coordinatorConfigurations/{configurationName}" - } + return deserialized # type: ignore def _update_on_coordinator_initial( self, resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: Union[_models.ServerConfiguration, IO], + parameters: Union[_models.ServerConfiguration, IO[bytes]], **kwargs: Any - ) -> _models.ServerConfiguration: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -707,7 +682,7 @@ def _update_on_coordinator_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.ServerConfiguration] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -717,7 +692,7 @@ def _update_on_coordinator_initial( else: _json = self._serialize.body(parameters, "ServerConfiguration") - request = build_update_on_coordinator_request( + _request = build_update_on_coordinator_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_name, @@ -726,46 +701,42 @@ def _update_on_coordinator_initial( content_type=content_type, json=_json, content=_content, - template_url=self._update_on_coordinator_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("ServerConfiguration", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _update_on_coordinator_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/coordinatorConfigurations/{configurationName}" - } - @overload def begin_update_on_coordinator( self, @@ -791,14 +762,6 @@ def begin_update_on_coordinator( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation 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 ServerConfiguration or the result of cls(response) :rtype: @@ -812,7 +775,7 @@ def begin_update_on_coordinator( resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -827,18 +790,10 @@ def begin_update_on_coordinator( :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str :param parameters: The required parameters for updating a cluster configuration. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either ServerConfiguration or the result of cls(response) :rtype: @@ -852,7 +807,7 @@ def begin_update_on_coordinator( resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: Union[_models.ServerConfiguration, IO], + parameters: Union[_models.ServerConfiguration, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.ServerConfiguration]: """Updates configuration of coordinator in a cluster. @@ -865,19 +820,8 @@ def begin_update_on_coordinator( :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str :param parameters: The required parameters for updating a cluster configuration. Is either a - ServerConfiguration type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + ServerConfiguration type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration or IO[bytes] :return: An instance of LROPoller that returns either ServerConfiguration or the result of cls(response) :rtype: @@ -906,12 +850,13 @@ def begin_update_on_coordinator( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = self._deserialize("ServerConfiguration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -923,17 +868,15 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.ServerConfiguration].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) # type: ignore - - begin_update_on_coordinator.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/coordinatorConfigurations/{configurationName}" - } + return LROPoller[_models.ServerConfiguration]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) @distributed_trace def get_node( @@ -948,12 +891,11 @@ def get_node( :type cluster_name: str :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServerConfiguration or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -967,22 +909,20 @@ def get_node( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ServerConfiguration] = kwargs.pop("cls", None) - request = build_get_node_request( + _request = build_get_node_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_node.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -992,26 +932,22 @@ def get_node( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = self._deserialize("ServerConfiguration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get_node.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/nodeConfigurations/{configurationName}" - } + return deserialized # type: ignore def _update_on_node_initial( self, resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: Union[_models.ServerConfiguration, IO], + parameters: Union[_models.ServerConfiguration, IO[bytes]], **kwargs: Any - ) -> _models.ServerConfiguration: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1024,7 +960,7 @@ def _update_on_node_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.ServerConfiguration] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -1034,7 +970,7 @@ def _update_on_node_initial( else: _json = self._serialize.body(parameters, "ServerConfiguration") - request = build_update_on_node_request( + _request = build_update_on_node_request( resource_group_name=resource_group_name, cluster_name=cluster_name, configuration_name=configuration_name, @@ -1043,46 +979,42 @@ def _update_on_node_initial( content_type=content_type, json=_json, content=_content, - template_url=self._update_on_node_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("ServerConfiguration", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _update_on_node_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/nodeConfigurations/{configurationName}" - } - @overload def begin_update_on_node( self, @@ -1108,14 +1040,6 @@ def begin_update_on_node( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation 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 ServerConfiguration or the result of cls(response) :rtype: @@ -1129,7 +1053,7 @@ def begin_update_on_node( resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -1144,18 +1068,10 @@ def begin_update_on_node( :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str :param parameters: The required parameters for updating a cluster configuration. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either ServerConfiguration or the result of cls(response) :rtype: @@ -1169,7 +1085,7 @@ def begin_update_on_node( resource_group_name: str, cluster_name: str, configuration_name: str, - parameters: Union[_models.ServerConfiguration, IO], + parameters: Union[_models.ServerConfiguration, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.ServerConfiguration]: """Updates configuration of worker nodes in a cluster. @@ -1182,19 +1098,8 @@ def begin_update_on_node( :param configuration_name: The name of the cluster configuration. Required. :type configuration_name: str :param parameters: The required parameters for updating a cluster configuration. Is either a - ServerConfiguration type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + ServerConfiguration type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.ServerConfiguration or IO[bytes] :return: An instance of LROPoller that returns either ServerConfiguration or the result of cls(response) :rtype: @@ -1223,12 +1128,13 @@ def begin_update_on_node( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("ServerConfiguration", pipeline_response) + deserialized = self._deserialize("ServerConfiguration", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -1240,14 +1146,12 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.ServerConfiguration].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) # type: ignore - - begin_update_on_node.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/nodeConfigurations/{configurationName}" - } + return LROPoller[_models.ServerConfiguration]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_firewall_rules_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_firewall_rules_operations.py index df4be60705ed..e4fb87dc12eb 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_firewall_rules_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_firewall_rules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,8 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -229,10 +234,10 @@ def _create_or_update_initial( resource_group_name: str, cluster_name: str, firewall_rule_name: str, - parameters: Union[_models.FirewallRule, IO], + parameters: Union[_models.FirewallRule, IO[bytes]], **kwargs: Any - ) -> _models.FirewallRule: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -245,7 +250,7 @@ def _create_or_update_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.FirewallRule] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -255,7 +260,7 @@ def _create_or_update_initial( else: _json = self._serialize.body(parameters, "FirewallRule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, cluster_name=cluster_name, firewall_rule_name=firewall_rule_name, @@ -264,46 +269,42 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("FirewallRule", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("FirewallRule", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _create_or_update_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } - @overload def begin_create_or_update( self, @@ -329,14 +330,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either FirewallRule or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.FirewallRule] @@ -349,7 +342,7 @@ def begin_create_or_update( resource_group_name: str, cluster_name: str, firewall_rule_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -364,18 +357,10 @@ def begin_create_or_update( :param firewall_rule_name: The name of the cluster firewall rule. Required. :type firewall_rule_name: str :param parameters: The required parameters for creating or updating a firewall rule. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either FirewallRule or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.FirewallRule] @@ -388,7 +373,7 @@ def begin_create_or_update( resource_group_name: str, cluster_name: str, firewall_rule_name: str, - parameters: Union[_models.FirewallRule, IO], + parameters: Union[_models.FirewallRule, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.FirewallRule]: """Creates a new cluster firewall rule or updates an existing cluster firewall rule. @@ -401,19 +386,8 @@ def begin_create_or_update( :param firewall_rule_name: The name of the cluster firewall rule. Required. :type firewall_rule_name: str :param parameters: The required parameters for creating or updating a firewall rule. Is either - a FirewallRule type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.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 - :keyword str continuation_token: A continuation 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. + a FirewallRule type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.FirewallRule or IO[bytes] :return: An instance of LROPoller that returns either FirewallRule or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.FirewallRule] @@ -441,12 +415,13 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("FirewallRule", pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -458,22 +433,20 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.FirewallRule].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) # type: ignore - - begin_create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } + return LROPoller[_models.FirewallRule]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements + def _delete_initial( self, resource_group_name: str, cluster_name: str, firewall_rule_name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -485,29 +458,32 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, cluster_name=cluster_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -519,12 +495,12 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _delete_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } + return deserialized # type: ignore @distributed_trace def begin_delete( @@ -539,14 +515,6 @@ def begin_delete( :type cluster_name: str :param firewall_rule_name: The name of the cluster firewall rule. Required. :type firewall_rule_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -560,7 +528,7 @@ def begin_delete( lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, firewall_rule_name=firewall_rule_name, @@ -570,11 +538,12 @@ def begin_delete( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: PollingMethod = cast( @@ -585,17 +554,13 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_delete.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def get( @@ -610,12 +575,11 @@ def get( :type cluster_name: str :param firewall_rule_name: The name of the cluster firewall rule. Required. :type firewall_rule_name: 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.cosmosdbforpostgresql.models.FirewallRule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -629,22 +593,20 @@ def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.FirewallRule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, firewall_rule_name=firewall_rule_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -654,16 +616,12 @@ def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("FirewallRule", pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" - } + return deserialized # type: ignore @distributed_trace def list_by_cluster( @@ -676,7 +634,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either FirewallRule or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.FirewallRule] :raises ~azure.core.exceptions.HttpResponseError: @@ -687,7 +644,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.FirewallRuleListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -698,17 +655,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -720,13 +675,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("FirewallRuleListResult", pipeline_response) @@ -736,11 +690,11 @@ def extract_data(pipeline_response): return None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -752,7 +706,3 @@ def get_next(next_link=None): return pipeline_response return ItemPaged(get_next, extract_data) - - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules" - } diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_operations.py index 3e59b447ad00..2332a22c7a7e 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,7 +6,8 @@ # 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 +import sys +from typing import Any, Callable, Dict, Iterable, Optional, Type, TypeVar import urllib.parse from azure.core.exceptions import ( @@ -19,16 +20,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -78,7 +81,6 @@ def __init__(self, *args, **kwargs): def list(self, **kwargs: Any) -> Iterable["_models.Operation"]: """Lists all of the available REST API operations. - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Operation or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Operation] :raises ~azure.core.exceptions.HttpResponseError: @@ -89,7 +91,7 @@ def list(self, **kwargs: Any) -> Iterable["_models.Operation"]: api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.OperationListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -100,14 +102,12 @@ def list(self, **kwargs: Any) -> Iterable["_models.Operation"]: def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -119,13 +119,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("OperationListResult", pipeline_response) @@ -135,11 +134,11 @@ def extract_data(pipeline_response): return None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -151,5 +150,3 @@ def get_next(next_link=None): return pipeline_response return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/providers/Microsoft.DBforPostgreSQL/operations"} diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_private_endpoint_connections_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_private_endpoint_connections_operations.py index d9515b885f7b..bcffa114aab5 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_private_endpoint_connections_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_private_endpoint_connections_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,8 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -253,7 +258,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either PrivateEndpointConnection or the result of cls(response) :rtype: @@ -266,7 +270,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.PrivateEndpointConnectionListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -277,17 +281,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -299,13 +301,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("PrivateEndpointConnectionListResult", pipeline_response) @@ -315,11 +316,11 @@ def extract_data(pipeline_response): return None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -332,10 +333,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections" - } - @distributed_trace def get( self, resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, **kwargs: Any @@ -350,12 +347,11 @@ def get( :param private_endpoint_connection_name: The name of the private endpoint connection associated with the cluster. Required. :type private_endpoint_connection_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: PrivateEndpointConnection or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.PrivateEndpointConnection :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -369,22 +365,20 @@ def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.PrivateEndpointConnection] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_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"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -394,26 +388,22 @@ def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } + return deserialized # type: ignore def _create_or_update_initial( self, resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, - parameters: Union[_models.PrivateEndpointConnection, IO], + parameters: Union[_models.PrivateEndpointConnection, IO[bytes]], **kwargs: Any - ) -> _models.PrivateEndpointConnection: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -426,7 +416,7 @@ def _create_or_update_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PrivateEndpointConnection] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -436,7 +426,7 @@ def _create_or_update_initial( else: _json = self._serialize.body(parameters, "PrivateEndpointConnection") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, cluster_name=cluster_name, private_endpoint_connection_name=private_endpoint_connection_name, @@ -445,46 +435,42 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _create_or_update_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } - @overload def begin_create_or_update( self, @@ -512,14 +498,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either PrivateEndpointConnection or the result of cls(response) :rtype: @@ -533,7 +511,7 @@ def begin_create_or_update( resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -550,18 +528,10 @@ def begin_create_or_update( :type private_endpoint_connection_name: str :param parameters: The required parameters for approving a private endpoint connection. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either PrivateEndpointConnection or the result of cls(response) :rtype: @@ -575,7 +545,7 @@ def begin_create_or_update( resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, - parameters: Union[_models.PrivateEndpointConnection, IO], + parameters: Union[_models.PrivateEndpointConnection, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.PrivateEndpointConnection]: """Approves or Rejects a private endpoint connection with a given name. @@ -589,19 +559,9 @@ def begin_create_or_update( with the cluster. Required. :type private_endpoint_connection_name: str :param parameters: The required parameters for approving a private endpoint connection. Is - either a PrivateEndpointConnection type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.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 - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + either a PrivateEndpointConnection type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.PrivateEndpointConnection or + IO[bytes] :return: An instance of LROPoller that returns either PrivateEndpointConnection or the result of cls(response) :rtype: @@ -630,12 +590,13 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -647,22 +608,20 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.PrivateEndpointConnection].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) # type: ignore - - begin_create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } + return LROPoller[_models.PrivateEndpointConnection]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements + def _delete_initial( self, resource_group_name: str, cluster_name: str, private_endpoint_connection_name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -674,29 +633,32 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, cluster_name=cluster_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"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -708,12 +670,12 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _delete_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } + return deserialized # type: ignore @distributed_trace def begin_delete( @@ -729,14 +691,6 @@ def begin_delete( :param private_endpoint_connection_name: The name of the private endpoint connection associated with the cluster. Required. :type private_endpoint_connection_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -750,7 +704,7 @@ def begin_delete( lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, private_endpoint_connection_name=private_endpoint_connection_name, @@ -760,11 +714,12 @@ def begin_delete( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: PollingMethod = cast( @@ -775,14 +730,10 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_delete.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" - } + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_private_link_resources_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_private_link_resources_operations.py index 22a5d2c4956d..9e21e5d27c60 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_private_link_resources_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_private_link_resources_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,7 +6,8 @@ # 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 +import sys +from typing import Any, Callable, Dict, Iterable, Optional, Type, TypeVar import urllib.parse from azure.core.exceptions import ( @@ -19,16 +20,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -149,7 +152,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either PrivateLinkResource or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.PrivateLinkResource] @@ -161,7 +163,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.PrivateLinkResourceListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -172,17 +174,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -194,13 +194,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("PrivateLinkResourceListResult", pipeline_response) @@ -210,11 +209,11 @@ def extract_data(pipeline_response): return None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -227,10 +226,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateLinkResources" - } - @distributed_trace def get( self, resource_group_name: str, cluster_name: str, private_link_resource_name: str, **kwargs: Any @@ -244,12 +239,11 @@ def get( :type cluster_name: str :param private_link_resource_name: The name of the private link resource. Required. :type private_link_resource_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: PrivateLinkResource or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.PrivateLinkResource :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -263,22 +257,20 @@ def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.PrivateLinkResource] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, private_link_resource_name=private_link_resource_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -288,13 +280,9 @@ def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("PrivateLinkResource", pipeline_response) + deserialized = self._deserialize("PrivateLinkResource", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateLinkResources/{privateLinkResourceName}" - } + return deserialized # type: ignore diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_roles_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_roles_operations.py index dafc7280444c..29eed33963ec 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_roles_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_roles_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from io import IOBase -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +import sys +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,8 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -235,12 +240,11 @@ def get(self, resource_group_name: str, cluster_name: str, role_name: str, **kwa :type cluster_name: str :param role_name: The name of the cluster role. Required. :type role_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Role or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.Role :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -254,22 +258,20 @@ def get(self, resource_group_name: str, cluster_name: str, role_name: str, **kwa api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.Role] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, role_name=role_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -279,26 +281,22 @@ def get(self, resource_group_name: str, cluster_name: str, role_name: str, **kwa error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("Role", pipeline_response) + deserialized = self._deserialize("Role", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } + return deserialized # type: ignore def _create_initial( self, resource_group_name: str, cluster_name: str, role_name: str, - parameters: Union[_models.Role, IO], + parameters: Union[_models.Role, IO[bytes]], **kwargs: Any - ) -> _models.Role: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -311,7 +309,7 @@ def _create_initial( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Role] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -321,7 +319,7 @@ def _create_initial( else: _json = self._serialize.body(parameters, "Role") - request = build_create_request( + _request = build_create_request( resource_group_name=resource_group_name, cluster_name=cluster_name, role_name=role_name, @@ -330,46 +328,42 @@ def _create_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) response_headers = {} - if response.status_code == 200: - deserialized = self._deserialize("Role", pipeline_response) - if response.status_code == 201: response_headers["location"] = self._deserialize("str", response.headers.get("location")) response_headers["azure-async-operation"] = self._deserialize( "str", response.headers.get("azure-async-operation") ) - deserialized = self._deserialize("Role", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore return deserialized # type: ignore - _create_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } - @overload def begin_create( self, @@ -395,14 +389,6 @@ def begin_create( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation 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 Role or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Role] :raises ~azure.core.exceptions.HttpResponseError: @@ -414,7 +400,7 @@ def begin_create( resource_group_name: str, cluster_name: str, role_name: str, - parameters: IO, + parameters: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -429,18 +415,10 @@ def begin_create( :param role_name: The name of the cluster role. Required. :type role_name: str :param parameters: The required parameters for creating or updating a role. Required. - :type parameters: IO + :type parameters: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Role or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Role] :raises ~azure.core.exceptions.HttpResponseError: @@ -452,7 +430,7 @@ def begin_create( resource_group_name: str, cluster_name: str, role_name: str, - parameters: Union[_models.Role, IO], + parameters: Union[_models.Role, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.Role]: """Creates a new role or updates an existing role. @@ -465,19 +443,8 @@ def begin_create( :param role_name: The name of the cluster role. Required. :type role_name: str :param parameters: The required parameters for creating or updating a role. Is either a Role - type or a IO type. Required. - :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.Role or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/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. + type or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.cosmosdbforpostgresql.models.Role or IO[bytes] :return: An instance of LROPoller that returns either Role or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.cosmosdbforpostgresql.models.Role] :raises ~azure.core.exceptions.HttpResponseError: @@ -504,12 +471,13 @@ def begin_create( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Role", pipeline_response) + deserialized = self._deserialize("Role", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: @@ -521,22 +489,20 @@ def get_long_running_output(pipeline_response): else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.Role].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) # type: ignore - - begin_create.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } + return LROPoller[_models.Role]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements + def _delete_initial( self, resource_group_name: str, cluster_name: str, role_name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -548,29 +514,32 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[None] = kwargs.pop("cls", None) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, cluster_name=cluster_name, role_name=role_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) - _stream = False + _decompress = kwargs.pop("decompress", True) + _stream = True pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) @@ -582,12 +551,12 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements "str", response.headers.get("azure-async-operation") ) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, response_headers) + return cls(pipeline_response, deserialized, response_headers) # type: ignore - _delete_initial.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } + return deserialized # type: ignore @distributed_trace def begin_delete( @@ -602,14 +571,6 @@ def begin_delete( :type cluster_name: str :param role_name: The name of the cluster role. Required. :type role_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -623,7 +584,7 @@ def begin_delete( lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, cluster_name=cluster_name, role_name=role_name, @@ -633,11 +594,12 @@ def begin_delete( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: polling_method: PollingMethod = cast( @@ -648,17 +610,13 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_delete.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" - } + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def list_by_cluster(self, resource_group_name: str, cluster_name: str, **kwargs: Any) -> Iterable["_models.Role"]: @@ -669,7 +627,6 @@ def list_by_cluster(self, resource_group_name: str, cluster_name: str, **kwargs: :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Role or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.Role] :raises ~azure.core.exceptions.HttpResponseError: @@ -680,7 +637,7 @@ def list_by_cluster(self, resource_group_name: str, cluster_name: str, **kwargs: api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.RoleListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -691,17 +648,15 @@ def list_by_cluster(self, resource_group_name: str, cluster_name: str, **kwargs: def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -713,13 +668,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("RoleListResult", pipeline_response) @@ -729,11 +683,11 @@ def extract_data(pipeline_response): return None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -745,7 +699,3 @@ def get_next(next_link=None): return pipeline_response return ItemPaged(get_next, extract_data) - - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles" - } diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_servers_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_servers_operations.py index 062962f92834..e5241a173ba8 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_servers_operations.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/azure/mgmt/cosmosdbforpostgresql/operations/_servers_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,7 +6,8 @@ # 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 +import sys +from typing import Any, Callable, Dict, Iterable, Optional, Type, TypeVar import urllib.parse from azure.core.exceptions import ( @@ -19,16 +20,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -149,7 +152,6 @@ def list_by_cluster( :type resource_group_name: str :param cluster_name: The name of the cluster. Required. :type cluster_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ClusterServer or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.cosmosdbforpostgresql.models.ClusterServer] :raises ~azure.core.exceptions.HttpResponseError: @@ -160,7 +162,7 @@ def list_by_cluster( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterServerListResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -171,17 +173,15 @@ def list_by_cluster( def prepare_request(next_link=None): if not next_link: - request = build_list_by_cluster_request( + _request = build_list_by_cluster_request( resource_group_name=resource_group_name, cluster_name=cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_cluster.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -193,13 +193,12 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ClusterServerListResult", pipeline_response) @@ -209,11 +208,11 @@ def extract_data(pipeline_response): return None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -226,10 +225,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_cluster.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers" - } - @distributed_trace def get( self, resource_group_name: str, cluster_name: str, server_name: str, **kwargs: Any @@ -243,12 +238,11 @@ def get( :type cluster_name: str :param server_name: The name of the server. Required. :type server_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ClusterServer or the result of cls(response) :rtype: ~azure.mgmt.cosmosdbforpostgresql.models.ClusterServer :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -262,22 +256,20 @@ def get( api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) cls: ClsType[_models.ClusterServer] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, cluster_name=cluster_name, server_name=server_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) + _request.url = self._client.format_url(_request.url) _stream = False pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -287,13 +279,9 @@ def get( error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = self._deserialize("ClusterServer", pipeline_response) + deserialized = self._deserialize("ClusterServer", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers/{serverName}" - } + return deserialized # type: ignore diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/check_name_availability.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/check_name_availability.py index 75318e459db9..67a3e63326a7 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/check_name_availability.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/check_name_availability.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_add_node.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_add_node.py index 1b38a3b58d21..d0735785c95f 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_add_node.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_add_node.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_burstablev1.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_burstablev1.py index 1494b405d365..b016eefa7eef 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_burstablev1.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_burstablev1.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_burstablev2.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_burstablev2.py index d0dabee3af30..d274b5a48256 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_burstablev2.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_burstablev2.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_custom_database_name.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_custom_database_name.py new file mode 100644 index 000000000000..1c72f01b06db --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_custom_database_name.py @@ -0,0 +1,60 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential + +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-cosmosdbforpostgresql +# USAGE + python cluster_create_custom_database_name.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = CosmosdbForPostgresqlMgmtClient( + credential=DefaultAzureCredential(), + subscription_id="ffffffff-ffff-ffff-ffff-ffffffffffff", + ) + + response = client.clusters.begin_create( + resource_group_name="TestGroup", + cluster_name="testcluster-custom-db-name", + parameters={ + "location": "westus", + "properties": { + "administratorLoginPassword": "password", + "citusVersion": "11.3", + "coordinatorEnablePublicIpAccess": True, + "coordinatorServerEdition": "GeneralPurpose", + "coordinatorStorageQuotaInMb": 131072, + "coordinatorVCores": 8, + "databaseName": "testdbname", + "enableHa": True, + "enableShardsOnCoordinator": True, + "nodeCount": 0, + "postgresqlVersion": "15", + "preferredPrimaryZone": "1", + }, + "tags": {"owner": "JohnDoe"}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/preview/2023-03-02-preview/examples/ClusterCreateCustomDatabaseName.json +if __name__ == "__main__": + main() diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_multi_node.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_multi_node.py index a97ba0dc5139..eb65fd72c047 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_multi_node.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_multi_node.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_pitr.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_pitr.py index e094d95a94ae..86e9b1d0a625 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_pitr.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_pitr.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_read_replica.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_read_replica.py index 2f773cd44bee..737de6ef431c 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_read_replica.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_read_replica.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_single_node.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_single_node.py index 3abebedc0be2..a5d4040c5a1f 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_single_node.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_single_node.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_with_aad.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_with_aad.py new file mode 100644 index 000000000000..d19e3155f1bb --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_with_aad.py @@ -0,0 +1,75 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential + +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-cosmosdbforpostgresql +# USAGE + python cluster_create_with_aad.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = CosmosdbForPostgresqlMgmtClient( + credential=DefaultAzureCredential(), + subscription_id="ffffffff-ffff-ffff-ffff-ffffffffffff", + ) + + response = client.clusters.begin_create( + resource_group_name="TestGroup", + cluster_name="testcluster-cmk", + parameters={ + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-usermanagedidentity": {} + }, + }, + "location": "westus", + "properties": { + "administratorLoginPassword": "password", + "citusVersion": "12.1", + "coordinatorEnablePublicIpAccess": True, + "coordinatorServerEdition": "GeneralPurpose", + "coordinatorStorageQuotaInMb": 524288, + "coordinatorVCores": 4, + "dataEncryption": { + "primaryKeyUri": "https://test-kv.vault.azure.net/keys/test-key1/fffffffffffffffffffffffffffffff", + "primaryUserAssignedIdentityId": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-usermanagedidentity", + "type": "AzureKeyVault", + }, + "databaseName": "citus", + "enableHa": False, + "enableShardsOnCoordinator": False, + "nodeCount": 3, + "nodeEnablePublicIpAccess": False, + "nodeServerEdition": "MemoryOptimized", + "nodeStorageQuotaInMb": 524288, + "nodeVCores": 8, + "postgresqlVersion": "15", + "preferredPrimaryZone": "1", + }, + "tags": {}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/preview/2023-03-02-preview/examples/ClusterCreateWithAAD.json +if __name__ == "__main__": + main() diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_with_cmk.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_with_cmk.py new file mode 100644 index 000000000000..9d2f95c8ac36 --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_create_with_cmk.py @@ -0,0 +1,75 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential + +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-cosmosdbforpostgresql +# USAGE + python cluster_create_with_cmk.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = CosmosdbForPostgresqlMgmtClient( + credential=DefaultAzureCredential(), + subscription_id="ffffffff-ffff-ffff-ffff-ffffffffffff", + ) + + response = client.clusters.begin_create( + resource_group_name="TestGroup", + cluster_name="testcluster-cmk", + parameters={ + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-usermanagedidentity": {} + }, + }, + "location": "westus", + "properties": { + "administratorLoginPassword": "password", + "citusVersion": "12.1", + "coordinatorEnablePublicIpAccess": True, + "coordinatorServerEdition": "GeneralPurpose", + "coordinatorStorageQuotaInMb": 524288, + "coordinatorVCores": 4, + "dataEncryption": { + "primaryKeyUri": "https://test-kv.vault.azure.net/keys/test-key1/fffffffffffffffffffffffffffffff", + "primaryUserAssignedIdentityId": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-usermanagedidentity", + "type": "AzureKeyVault", + }, + "databaseName": "citus", + "enableHa": False, + "enableShardsOnCoordinator": False, + "nodeCount": 3, + "nodeEnablePublicIpAccess": False, + "nodeServerEdition": "MemoryOptimized", + "nodeStorageQuotaInMb": 524288, + "nodeVCores": 8, + "postgresqlVersion": "15", + "preferredPrimaryZone": "1", + }, + "tags": {}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/preview/2023-03-02-preview/examples/ClusterCreateWithCMK.json +if __name__ == "__main__": + main() diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_delete.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_delete.py index b5273912e993..6f40d6294675 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_delete.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_get.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_get.py index c03a465ac10b..56b5c11705c5 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_get.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_list.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_list.py index 526f8099e7a4..a8c2d851b5ba 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_list.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_list_by_resource_group.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_list_by_resource_group.py index c26681722869..fce44966425d 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_list_by_resource_group.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_list_by_resource_group.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_promote_read_replica.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_promote_read_replica.py index 538239f3a5cd..09f734806a1a 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_promote_read_replica.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_promote_read_replica.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_restart.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_restart.py index fa69e7cc41f8..f969577c724d 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_restart.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_restart.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_scale_compute.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_scale_compute.py index ffe9153b559d..8a29ad81a408 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_scale_compute.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_scale_compute.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_scale_storage.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_scale_storage.py index 9e2775b936fd..fa4e05de2f32 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_scale_storage.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_scale_storage.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_start.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_start.py index a062e4e9c59d..2f88869be249 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_start.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_start.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_stop.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_stop.py index 66a7b608fcb3..01d25d2e3836 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_stop.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_stop.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_update.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_update.py index 33cd470e28af..3cdb3bd55025 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_update.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_update_maintenance_window.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_update_maintenance_window.py index 1d52efe69c40..bb484792ebe2 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_update_maintenance_window.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/cluster_update_maintenance_window.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get.py index 8fbce22ef138..ab501823bade 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get_coordinator.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get_coordinator.py index c3c25491f109..6d16c0db4c9b 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get_coordinator.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get_coordinator.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get_node.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get_node.py index 948041dfa95d..9265be62bed4 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get_node.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_get_node.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_list_by_cluster.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_list_by_cluster.py index f649fb6d8e12..08d6ac392d6a 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_list_by_cluster.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_list_by_cluster.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_list_by_server.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_list_by_server.py index 2afa159f2f24..a4598c98a8a5 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_list_by_server.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_list_by_server.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_update_coordinator.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_update_coordinator.py index e171c09e2db4..2baf055fa701 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_update_coordinator.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_update_coordinator.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_update_node.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_update_node.py index e967d7624dc0..d127fb848920 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_update_node.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/configuration_update_node.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_create.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_create.py index 5c86933349be..3b7fd9a478fa 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_create.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_create.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_delete.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_delete.py index e0d9cc3a8958..22a4546cc836 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_delete.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_get.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_get.py index 34d58b3bdf2c..05943afb4206 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_get.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_list_by_cluster.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_list_by_cluster.py index f6d68c580188..1c96ac967631 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_list_by_cluster.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/firewall_rule_list_by_cluster.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/operation_list.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/operation_list.py index c95eacf0a300..9f6710418297 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/operation_list.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/operation_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connection_create_or_update.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connection_create_or_update.py index fcaace77b4fe..18232140968b 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connection_create_or_update.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connection_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_delete.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_delete.py index b0f4d9817916..85bcb0461a14 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_delete.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_get.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_get.py index cedd9ba5faa7..979001bd2c4f 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_get.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_list_by_cluster.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_list_by_cluster.py index ca4c553d57ab..a45c18a6b2f1 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_list_by_cluster.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_endpoint_connections_list_by_cluster.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_link_resource_list_by_cluster.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_link_resource_list_by_cluster.py index 9679a799862f..984f95c15564 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_link_resource_list_by_cluster.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_link_resource_list_by_cluster.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_link_resources_get.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_link_resources_get.py index a172c781c564..53e6668094ca 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_link_resources_get.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/private_link_resources_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_create.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_create.py index d66dcfde24b0..ebf7419694cb 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_create.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_create.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_delete.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_delete.py index 76e1175b83b6..d51e224d1368 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_delete.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_get.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_get.py index bd15597dc70e..d24ac18b5cfc 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_get.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_list_by_cluster.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_list_by_cluster.py index b205001c51c5..e2daf031b22c 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_list_by_cluster.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/role_list_by_cluster.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/server_get.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/server_get.py index 25f425c7c2d9..321f84b2beb3 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/server_get.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/server_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/server_list_by_cluster.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/server_list_by_cluster.py index eedd449eb11a..f1681333fee6 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/server_list_by_cluster.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_samples/server_list_by_cluster.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient """ diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/conftest.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/conftest.py new file mode 100644 index 000000000000..0073cf7be787 --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/conftest.py @@ -0,0 +1,43 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import os +import pytest +from dotenv import load_dotenv +from devtools_testutils import ( + test_proxy, + add_general_regex_sanitizer, + add_body_key_sanitizer, + add_header_regex_sanitizer, +) + +load_dotenv() + + +# aovid record sensitive identity information in recordings +@pytest.fixture(scope="session", autouse=True) +def add_sanitizers(test_proxy): + cosmosdbforpostgresqlmgmt_subscription_id = os.environ.get( + "AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000" + ) + cosmosdbforpostgresqlmgmt_tenant_id = os.environ.get("AZURE_TENANT_ID", "00000000-0000-0000-0000-000000000000") + cosmosdbforpostgresqlmgmt_client_id = os.environ.get("AZURE_CLIENT_ID", "00000000-0000-0000-0000-000000000000") + cosmosdbforpostgresqlmgmt_client_secret = os.environ.get( + "AZURE_CLIENT_SECRET", "00000000-0000-0000-0000-000000000000" + ) + add_general_regex_sanitizer( + regex=cosmosdbforpostgresqlmgmt_subscription_id, value="00000000-0000-0000-0000-000000000000" + ) + add_general_regex_sanitizer(regex=cosmosdbforpostgresqlmgmt_tenant_id, value="00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=cosmosdbforpostgresqlmgmt_client_id, value="00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer( + regex=cosmosdbforpostgresqlmgmt_client_secret, value="00000000-0000-0000-0000-000000000000" + ) + + add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]") + add_header_regex_sanitizer(key="Cookie", value="cookie;") + add_body_key_sanitizer(json_path="$..access_token", value="access_token") diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_clusters_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_clusters_operations.py new file mode 100644 index 000000000000..f8edccba467d --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_clusters_operations.py @@ -0,0 +1,242 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtClustersOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.clusters.list( + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_resource_group(self, resource_group): + response = self.client.clusters.list_by_resource_group( + resource_group_name=resource_group.name, + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create(self, resource_group): + response = self.client.clusters.begin_create( + resource_group_name=resource_group.name, + cluster_name="str", + parameters={ + "location": "str", + "aadAuthEnabled": "str", + "administratorLogin": "str", + "administratorLoginPassword": "str", + "authConfig": {"activeDirectoryAuth": "str", "passwordAuth": "str"}, + "citusVersion": "str", + "coordinatorEnablePublicIpAccess": bool, + "coordinatorServerEdition": "str", + "coordinatorStorageQuotaInMb": 0, + "coordinatorVCores": 0, + "dataEncryption": {"primaryKeyUri": "str", "primaryUserAssignedIdentityId": "str", "type": "str"}, + "databaseName": "str", + "earliestRestoreTime": "2020-02-20 00:00:00", + "enableGeoBackup": bool, + "enableHa": bool, + "enableShardsOnCoordinator": bool, + "id": "str", + "identity": { + "type": "str", + "userAssignedIdentities": {"str": {"clientId": "str", "principalId": "str"}}, + }, + "maintenanceWindow": {"customWindow": "str", "dayOfWeek": 0, "startHour": 0, "startMinute": 0}, + "name": "str", + "nodeCount": 0, + "nodeEnablePublicIpAccess": bool, + "nodeServerEdition": "str", + "nodeStorageQuotaInMb": 0, + "nodeVCores": 0, + "passwordEnabled": "str", + "pointInTimeUTC": "2020-02-20 00:00:00", + "postgresqlVersion": "str", + "preferredPrimaryZone": "str", + "privateEndpointConnections": [ + { + "groupIds": ["str"], + "id": "str", + "name": "str", + "privateEndpoint": {"id": "str"}, + "privateLinkServiceConnectionState": { + "actionsRequired": "str", + "description": "str", + "status": "str", + }, + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + } + ], + "provisioningState": "str", + "readReplicas": ["str"], + "serverNames": [{"fullyQualifiedDomainName": "str", "name": "str"}], + "sourceLocation": "str", + "sourceResourceId": "str", + "state": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "tags": {"str": "str"}, + "type": "str", + }, + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.clusters.get( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.clusters.begin_delete( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_update(self, resource_group): + response = self.client.clusters.begin_update( + resource_group_name=resource_group.name, + cluster_name="str", + parameters={ + "administratorLoginPassword": "str", + "citusVersion": "str", + "coordinatorEnablePublicIpAccess": bool, + "coordinatorServerEdition": "str", + "coordinatorStorageQuotaInMb": 0, + "coordinatorVCores": 0, + "enableHa": bool, + "enableShardsOnCoordinator": bool, + "identity": { + "type": "str", + "userAssignedIdentities": {"str": {"clientId": "str", "principalId": "str"}}, + }, + "maintenanceWindow": {"customWindow": "str", "dayOfWeek": 0, "startHour": 0, "startMinute": 0}, + "nodeCount": 0, + "nodeEnablePublicIpAccess": bool, + "nodeServerEdition": "str", + "nodeStorageQuotaInMb": 0, + "nodeVCores": 0, + "postgresqlVersion": "str", + "preferredPrimaryZone": "str", + "tags": {"str": "str"}, + }, + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_restart(self, resource_group): + response = self.client.clusters.begin_restart( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_start(self, resource_group): + response = self.client.clusters.begin_start( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_stop(self, resource_group): + response = self.client.clusters.begin_stop( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_promote_read_replica(self, resource_group): + response = self.client.clusters.begin_promote_read_replica( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_check_name_availability(self, resource_group): + response = self.client.clusters.check_name_availability( + name_availability_request={"name": "str", "type": "Microsoft.DBforPostgreSQL/serverGroupsv2"}, + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_clusters_operations_async.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_clusters_operations_async.py new file mode 100644 index 000000000000..ffd085c9f03c --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_clusters_operations_async.py @@ -0,0 +1,257 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql.aio import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtClustersOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.clusters.list( + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_resource_group(self, resource_group): + response = self.client.clusters.list_by_resource_group( + resource_group_name=resource_group.name, + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create(self, resource_group): + response = await ( + await self.client.clusters.begin_create( + resource_group_name=resource_group.name, + cluster_name="str", + parameters={ + "location": "str", + "aadAuthEnabled": "str", + "administratorLogin": "str", + "administratorLoginPassword": "str", + "authConfig": {"activeDirectoryAuth": "str", "passwordAuth": "str"}, + "citusVersion": "str", + "coordinatorEnablePublicIpAccess": bool, + "coordinatorServerEdition": "str", + "coordinatorStorageQuotaInMb": 0, + "coordinatorVCores": 0, + "dataEncryption": {"primaryKeyUri": "str", "primaryUserAssignedIdentityId": "str", "type": "str"}, + "databaseName": "str", + "earliestRestoreTime": "2020-02-20 00:00:00", + "enableGeoBackup": bool, + "enableHa": bool, + "enableShardsOnCoordinator": bool, + "id": "str", + "identity": { + "type": "str", + "userAssignedIdentities": {"str": {"clientId": "str", "principalId": "str"}}, + }, + "maintenanceWindow": {"customWindow": "str", "dayOfWeek": 0, "startHour": 0, "startMinute": 0}, + "name": "str", + "nodeCount": 0, + "nodeEnablePublicIpAccess": bool, + "nodeServerEdition": "str", + "nodeStorageQuotaInMb": 0, + "nodeVCores": 0, + "passwordEnabled": "str", + "pointInTimeUTC": "2020-02-20 00:00:00", + "postgresqlVersion": "str", + "preferredPrimaryZone": "str", + "privateEndpointConnections": [ + { + "groupIds": ["str"], + "id": "str", + "name": "str", + "privateEndpoint": {"id": "str"}, + "privateLinkServiceConnectionState": { + "actionsRequired": "str", + "description": "str", + "status": "str", + }, + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + } + ], + "provisioningState": "str", + "readReplicas": ["str"], + "serverNames": [{"fullyQualifiedDomainName": "str", "name": "str"}], + "sourceLocation": "str", + "sourceResourceId": "str", + "state": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "tags": {"str": "str"}, + "type": "str", + }, + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.clusters.get( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.clusters.begin_delete( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_update(self, resource_group): + response = await ( + await self.client.clusters.begin_update( + resource_group_name=resource_group.name, + cluster_name="str", + parameters={ + "administratorLoginPassword": "str", + "citusVersion": "str", + "coordinatorEnablePublicIpAccess": bool, + "coordinatorServerEdition": "str", + "coordinatorStorageQuotaInMb": 0, + "coordinatorVCores": 0, + "enableHa": bool, + "enableShardsOnCoordinator": bool, + "identity": { + "type": "str", + "userAssignedIdentities": {"str": {"clientId": "str", "principalId": "str"}}, + }, + "maintenanceWindow": {"customWindow": "str", "dayOfWeek": 0, "startHour": 0, "startMinute": 0}, + "nodeCount": 0, + "nodeEnablePublicIpAccess": bool, + "nodeServerEdition": "str", + "nodeStorageQuotaInMb": 0, + "nodeVCores": 0, + "postgresqlVersion": "str", + "preferredPrimaryZone": "str", + "tags": {"str": "str"}, + }, + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_restart(self, resource_group): + response = await ( + await self.client.clusters.begin_restart( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_start(self, resource_group): + response = await ( + await self.client.clusters.begin_start( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_stop(self, resource_group): + response = await ( + await self.client.clusters.begin_stop( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_promote_read_replica(self, resource_group): + response = await ( + await self.client.clusters.begin_promote_read_replica( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_check_name_availability(self, resource_group): + response = await self.client.clusters.check_name_availability( + name_availability_request={"name": "str", "type": "Microsoft.DBforPostgreSQL/serverGroupsv2"}, + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_configurations_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_configurations_operations.py new file mode 100644 index 000000000000..dd0c2889c478 --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_configurations_operations.py @@ -0,0 +1,151 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtConfigurationsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_server(self, resource_group): + response = self.client.configurations.list_by_server( + resource_group_name=resource_group.name, + cluster_name="str", + server_name="str", + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_cluster(self, resource_group): + response = self.client.configurations.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.configurations.get( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get_coordinator(self, resource_group): + response = self.client.configurations.get_coordinator( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_update_on_coordinator(self, resource_group): + response = self.client.configurations.begin_update_on_coordinator( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + parameters={ + "allowedValues": "str", + "dataType": "str", + "defaultValue": "str", + "description": "str", + "id": "str", + "name": "str", + "provisioningState": "str", + "requiresRestart": bool, + "source": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + "value": "str", + }, + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get_node(self, resource_group): + response = self.client.configurations.get_node( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_update_on_node(self, resource_group): + response = self.client.configurations.begin_update_on_node( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + parameters={ + "allowedValues": "str", + "dataType": "str", + "defaultValue": "str", + "description": "str", + "id": "str", + "name": "str", + "provisioningState": "str", + "requiresRestart": bool, + "source": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + "value": "str", + }, + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_configurations_operations_async.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_configurations_operations_async.py new file mode 100644 index 000000000000..f422279227b6 --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_configurations_operations_async.py @@ -0,0 +1,156 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql.aio import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtConfigurationsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_server(self, resource_group): + response = self.client.configurations.list_by_server( + resource_group_name=resource_group.name, + cluster_name="str", + server_name="str", + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_cluster(self, resource_group): + response = self.client.configurations.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.configurations.get( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get_coordinator(self, resource_group): + response = await self.client.configurations.get_coordinator( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_update_on_coordinator(self, resource_group): + response = await ( + await self.client.configurations.begin_update_on_coordinator( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + parameters={ + "allowedValues": "str", + "dataType": "str", + "defaultValue": "str", + "description": "str", + "id": "str", + "name": "str", + "provisioningState": "str", + "requiresRestart": bool, + "source": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + "value": "str", + }, + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get_node(self, resource_group): + response = await self.client.configurations.get_node( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_update_on_node(self, resource_group): + response = await ( + await self.client.configurations.begin_update_on_node( + resource_group_name=resource_group.name, + cluster_name="str", + configuration_name="str", + parameters={ + "allowedValues": "str", + "dataType": "str", + "defaultValue": "str", + "description": "str", + "id": "str", + "name": "str", + "provisioningState": "str", + "requiresRestart": bool, + "source": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + "value": "str", + }, + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_firewall_rules_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_firewall_rules_operations.py new file mode 100644 index 000000000000..3b5657c53768 --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_firewall_rules_operations.py @@ -0,0 +1,86 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtFirewallRulesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.firewall_rules.begin_create_or_update( + resource_group_name=resource_group.name, + cluster_name="str", + firewall_rule_name="str", + parameters={ + "endIpAddress": "str", + "startIpAddress": "str", + "id": "str", + "name": "str", + "provisioningState": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + }, + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.firewall_rules.begin_delete( + resource_group_name=resource_group.name, + cluster_name="str", + firewall_rule_name="str", + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.firewall_rules.get( + resource_group_name=resource_group.name, + cluster_name="str", + firewall_rule_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_cluster(self, resource_group): + response = self.client.firewall_rules.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_firewall_rules_operations_async.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_firewall_rules_operations_async.py new file mode 100644 index 000000000000..5b35b6d0ddb3 --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_firewall_rules_operations_async.py @@ -0,0 +1,91 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql.aio import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtFirewallRulesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.firewall_rules.begin_create_or_update( + resource_group_name=resource_group.name, + cluster_name="str", + firewall_rule_name="str", + parameters={ + "endIpAddress": "str", + "startIpAddress": "str", + "id": "str", + "name": "str", + "provisioningState": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + }, + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.firewall_rules.begin_delete( + resource_group_name=resource_group.name, + cluster_name="str", + firewall_rule_name="str", + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.firewall_rules.get( + resource_group_name=resource_group.name, + cluster_name="str", + firewall_rule_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_cluster(self, resource_group): + response = self.client.firewall_rules.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_operations.py new file mode 100644 index 000000000000..df11c886b8af --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_operations.py @@ -0,0 +1,29 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.operations.list( + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_operations_async.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_operations_async.py new file mode 100644 index 000000000000..17409bb36d2f --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_operations_async.py @@ -0,0 +1,30 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql.aio import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.operations.list( + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_endpoint_connections_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_endpoint_connections_operations.py new file mode 100644 index 000000000000..4e18777b0aa7 --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_endpoint_connections_operations.py @@ -0,0 +1,87 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtPrivateEndpointConnectionsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_cluster(self, resource_group): + response = self.client.private_endpoint_connections.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.private_endpoint_connections.get( + resource_group_name=resource_group.name, + cluster_name="str", + private_endpoint_connection_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.private_endpoint_connections.begin_create_or_update( + resource_group_name=resource_group.name, + cluster_name="str", + private_endpoint_connection_name="str", + parameters={ + "groupIds": ["str"], + "id": "str", + "name": "str", + "privateEndpoint": {"id": "str"}, + "privateLinkServiceConnectionState": {"actionsRequired": "str", "description": "str", "status": "str"}, + "provisioningState": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + }, + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.private_endpoint_connections.begin_delete( + resource_group_name=resource_group.name, + cluster_name="str", + private_endpoint_connection_name="str", + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_endpoint_connections_operations_async.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_endpoint_connections_operations_async.py new file mode 100644 index 000000000000..a4f4b3b116ac --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_endpoint_connections_operations_async.py @@ -0,0 +1,96 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql.aio import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtPrivateEndpointConnectionsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_cluster(self, resource_group): + response = self.client.private_endpoint_connections.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.private_endpoint_connections.get( + resource_group_name=resource_group.name, + cluster_name="str", + private_endpoint_connection_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.private_endpoint_connections.begin_create_or_update( + resource_group_name=resource_group.name, + cluster_name="str", + private_endpoint_connection_name="str", + parameters={ + "groupIds": ["str"], + "id": "str", + "name": "str", + "privateEndpoint": {"id": "str"}, + "privateLinkServiceConnectionState": { + "actionsRequired": "str", + "description": "str", + "status": "str", + }, + "provisioningState": "str", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "type": "str", + }, + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.private_endpoint_connections.begin_delete( + resource_group_name=resource_group.name, + cluster_name="str", + private_endpoint_connection_name="str", + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_link_resources_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_link_resources_operations.py new file mode 100644 index 000000000000..e3341324439a --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_link_resources_operations.py @@ -0,0 +1,44 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtPrivateLinkResourcesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_cluster(self, resource_group): + response = self.client.private_link_resources.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.private_link_resources.get( + resource_group_name=resource_group.name, + cluster_name="str", + private_link_resource_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_link_resources_operations_async.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_link_resources_operations_async.py new file mode 100644 index 000000000000..5540ca2dfb5e --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_private_link_resources_operations_async.py @@ -0,0 +1,45 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql.aio import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtPrivateLinkResourcesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_cluster(self, resource_group): + response = self.client.private_link_resources.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.private_link_resources.get( + resource_group_name=resource_group.name, + cluster_name="str", + private_link_resource_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_roles_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_roles_operations.py new file mode 100644 index 000000000000..5e74a715f5bd --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_roles_operations.py @@ -0,0 +1,89 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtRolesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.roles.get( + resource_group_name=resource_group.name, + cluster_name="str", + role_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create(self, resource_group): + response = self.client.roles.begin_create( + resource_group_name=resource_group.name, + cluster_name="str", + role_name="str", + parameters={ + "id": "str", + "name": "str", + "objectId": "str", + "password": "str", + "principalType": "str", + "provisioningState": "str", + "roleType": "user", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "tenantId": "str", + "type": "str", + }, + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.roles.begin_delete( + resource_group_name=resource_group.name, + cluster_name="str", + role_name="str", + api_version="2023-03-02-preview", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_cluster(self, resource_group): + response = self.client.roles.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_roles_operations_async.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_roles_operations_async.py new file mode 100644 index 000000000000..3987f9b1c73b --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_roles_operations_async.py @@ -0,0 +1,94 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql.aio import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtRolesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.roles.get( + resource_group_name=resource_group.name, + cluster_name="str", + role_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create(self, resource_group): + response = await ( + await self.client.roles.begin_create( + resource_group_name=resource_group.name, + cluster_name="str", + role_name="str", + parameters={ + "id": "str", + "name": "str", + "objectId": "str", + "password": "str", + "principalType": "str", + "provisioningState": "str", + "roleType": "user", + "systemData": { + "createdAt": "2020-02-20 00:00:00", + "createdBy": "str", + "createdByType": "str", + "lastModifiedAt": "2020-02-20 00:00:00", + "lastModifiedBy": "str", + "lastModifiedByType": "str", + }, + "tenantId": "str", + "type": "str", + }, + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.roles.begin_delete( + resource_group_name=resource_group.name, + cluster_name="str", + role_name="str", + api_version="2023-03-02-preview", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_cluster(self, resource_group): + response = self.client.roles.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_servers_operations.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_servers_operations.py new file mode 100644 index 000000000000..250543a93a4b --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_servers_operations.py @@ -0,0 +1,44 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtServersOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_cluster(self, resource_group): + response = self.client.servers.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.servers.get( + resource_group_name=resource_group.name, + cluster_name="str", + server_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_servers_operations_async.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_servers_operations_async.py new file mode 100644 index 000000000000..2ceb124afd4f --- /dev/null +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/generated_tests/test_cosmosdb_for_postgresql_mgmt_servers_operations_async.py @@ -0,0 +1,45 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +import pytest +from azure.mgmt.cosmosdbforpostgresql.aio import CosmosdbForPostgresqlMgmtClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestCosmosdbForPostgresqlMgmtServersOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(CosmosdbForPostgresqlMgmtClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_cluster(self, resource_group): + response = self.client.servers.list_by_cluster( + resource_group_name=resource_group.name, + cluster_name="str", + api_version="2023-03-02-preview", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.servers.get( + resource_group_name=resource_group.name, + cluster_name="str", + server_name="str", + api_version="2023-03-02-preview", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/setup.py b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/setup.py index 289a57e22229..8c6ad70b1100 100644 --- a/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/setup.py +++ b/sdk/cosmosdbforpostgresql/azure-mgmt-cosmosdbforpostgresql/setup.py @@ -74,9 +74,10 @@ "pytyped": ["py.typed"], }, install_requires=[ - "isodate<1.0.0,>=0.6.1", - "azure-common~=1.1", - "azure-mgmt-core>=1.3.2,<2.0.0", + "isodate>=0.6.1", + "typing-extensions>=4.6.0", + "azure-common>=1.1", + "azure-mgmt-core>=1.3.2", ], python_requires=">=3.8", )