|
| 1 | +# coding=utf-8 |
| 2 | +# -------------------------------------------------------------------------- |
| 3 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 5 | +# Code generated by Microsoft (R) AutoRest Code Generator. |
| 6 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
| 7 | +# -------------------------------------------------------------------------- |
| 8 | + |
| 9 | +from copy import deepcopy |
| 10 | +from typing import Any, Optional, TYPE_CHECKING, cast |
| 11 | +from typing_extensions import Self |
| 12 | + |
| 13 | +from azure.core.pipeline import policies |
| 14 | +from azure.core.rest import HttpRequest, HttpResponse |
| 15 | +from azure.core.settings import settings |
| 16 | +from azure.mgmt.core import ARMPipelineClient |
| 17 | +from azure.mgmt.core.policies import ARMAutoResourceProviderRegistrationPolicy |
| 18 | +from azure.mgmt.core.tools import get_arm_endpoints |
| 19 | + |
| 20 | +from . import models as _models |
| 21 | +from ._configuration import PostgreSQLManagementClientConfiguration |
| 22 | +from ._utils.serialization import Deserializer, Serializer |
| 23 | +from .operations import ( |
| 24 | + CheckNameAvailabilityOperations, |
| 25 | + ConfigurationsOperations, |
| 26 | + DatabasesOperations, |
| 27 | + FirewallRulesOperations, |
| 28 | + GetPrivateDnsZoneSuffixOperations, |
| 29 | + LocationBasedCapabilitiesOperations, |
| 30 | + Operations, |
| 31 | + ServersOperations, |
| 32 | + VirtualNetworkSubnetUsageOperations, |
| 33 | +) |
| 34 | + |
| 35 | +if TYPE_CHECKING: |
| 36 | + from azure.core import AzureClouds |
| 37 | + from azure.core.credentials import TokenCredential |
| 38 | + |
| 39 | + |
| 40 | +class PostgreSQLManagementClient: # pylint: disable=too-many-instance-attributes |
| 41 | + """The Azure Database for PostgreSQL management API provides create, read, update, and delete |
| 42 | + functionality for Azure PostgreSQL resources including servers, databases, firewall rules, |
| 43 | + network configuration, security alert policies, log files and configurations with new business |
| 44 | + model. |
| 45 | +
|
| 46 | + :ivar servers: ServersOperations operations |
| 47 | + :vartype servers: azure.mgmt.rdbms.postgresql_flexibleservers.operations.ServersOperations |
| 48 | + :ivar firewall_rules: FirewallRulesOperations operations |
| 49 | + :vartype firewall_rules: |
| 50 | + azure.mgmt.rdbms.postgresql_flexibleservers.operations.FirewallRulesOperations |
| 51 | + :ivar configurations: ConfigurationsOperations operations |
| 52 | + :vartype configurations: |
| 53 | + azure.mgmt.rdbms.postgresql_flexibleservers.operations.ConfigurationsOperations |
| 54 | + :ivar check_name_availability: CheckNameAvailabilityOperations operations |
| 55 | + :vartype check_name_availability: |
| 56 | + azure.mgmt.rdbms.postgresql_flexibleservers.operations.CheckNameAvailabilityOperations |
| 57 | + :ivar location_based_capabilities: LocationBasedCapabilitiesOperations operations |
| 58 | + :vartype location_based_capabilities: |
| 59 | + azure.mgmt.rdbms.postgresql_flexibleservers.operations.LocationBasedCapabilitiesOperations |
| 60 | + :ivar virtual_network_subnet_usage: VirtualNetworkSubnetUsageOperations operations |
| 61 | + :vartype virtual_network_subnet_usage: |
| 62 | + azure.mgmt.rdbms.postgresql_flexibleservers.operations.VirtualNetworkSubnetUsageOperations |
| 63 | + :ivar operations: Operations operations |
| 64 | + :vartype operations: azure.mgmt.rdbms.postgresql_flexibleservers.operations.Operations |
| 65 | + :ivar databases: DatabasesOperations operations |
| 66 | + :vartype databases: azure.mgmt.rdbms.postgresql_flexibleservers.operations.DatabasesOperations |
| 67 | + :ivar get_private_dns_zone_suffix: GetPrivateDnsZoneSuffixOperations operations |
| 68 | + :vartype get_private_dns_zone_suffix: |
| 69 | + azure.mgmt.rdbms.postgresql_flexibleservers.operations.GetPrivateDnsZoneSuffixOperations |
| 70 | + :param credential: Credential needed for the client to connect to Azure. Required. |
| 71 | + :type credential: ~azure.core.credentials.TokenCredential |
| 72 | + :param subscription_id: The ID of the target subscription. Required. |
| 73 | + :type subscription_id: str |
| 74 | + :param base_url: Service URL. Default value is None. |
| 75 | + :type base_url: str |
| 76 | + :keyword cloud_setting: The cloud setting for which to get the ARM endpoint. Default value is |
| 77 | + None. |
| 78 | + :paramtype cloud_setting: ~azure.core.AzureClouds |
| 79 | + :keyword api_version: Api Version. Default value is "2021-06-01". Note that overriding this |
| 80 | + default value may result in unsupported behavior. |
| 81 | + :paramtype api_version: str |
| 82 | + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no |
| 83 | + Retry-After header is present. |
| 84 | + """ |
| 85 | + |
| 86 | + def __init__( |
| 87 | + self, |
| 88 | + credential: "TokenCredential", |
| 89 | + subscription_id: str, |
| 90 | + base_url: Optional[str] = None, |
| 91 | + *, |
| 92 | + cloud_setting: Optional["AzureClouds"] = None, |
| 93 | + **kwargs: Any |
| 94 | + ) -> None: |
| 95 | + _cloud = cloud_setting or settings.current.azure_cloud # type: ignore |
| 96 | + _endpoints = get_arm_endpoints(_cloud) |
| 97 | + if not base_url: |
| 98 | + base_url = _endpoints["resource_manager"] |
| 99 | + credential_scopes = kwargs.pop("credential_scopes", _endpoints["credential_scopes"]) |
| 100 | + self._config = PostgreSQLManagementClientConfiguration( |
| 101 | + credential=credential, |
| 102 | + subscription_id=subscription_id, |
| 103 | + cloud_setting=cloud_setting, |
| 104 | + credential_scopes=credential_scopes, |
| 105 | + **kwargs |
| 106 | + ) |
| 107 | + |
| 108 | + _policies = kwargs.pop("policies", None) |
| 109 | + if _policies is None: |
| 110 | + _policies = [ |
| 111 | + policies.RequestIdPolicy(**kwargs), |
| 112 | + self._config.headers_policy, |
| 113 | + self._config.user_agent_policy, |
| 114 | + self._config.proxy_policy, |
| 115 | + policies.ContentDecodePolicy(**kwargs), |
| 116 | + ARMAutoResourceProviderRegistrationPolicy(), |
| 117 | + self._config.redirect_policy, |
| 118 | + self._config.retry_policy, |
| 119 | + self._config.authentication_policy, |
| 120 | + self._config.custom_hook_policy, |
| 121 | + self._config.logging_policy, |
| 122 | + policies.DistributedTracingPolicy(**kwargs), |
| 123 | + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, |
| 124 | + self._config.http_logging_policy, |
| 125 | + ] |
| 126 | + self._client: ARMPipelineClient = ARMPipelineClient(base_url=cast(str, base_url), policies=_policies, **kwargs) |
| 127 | + |
| 128 | + client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} |
| 129 | + self._serialize = Serializer(client_models) |
| 130 | + self._deserialize = Deserializer(client_models) |
| 131 | + self._serialize.client_side_validation = False |
| 132 | + self.servers = ServersOperations(self._client, self._config, self._serialize, self._deserialize) |
| 133 | + self.firewall_rules = FirewallRulesOperations(self._client, self._config, self._serialize, self._deserialize) |
| 134 | + self.configurations = ConfigurationsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 135 | + self.check_name_availability = CheckNameAvailabilityOperations( |
| 136 | + self._client, self._config, self._serialize, self._deserialize |
| 137 | + ) |
| 138 | + self.location_based_capabilities = LocationBasedCapabilitiesOperations( |
| 139 | + self._client, self._config, self._serialize, self._deserialize |
| 140 | + ) |
| 141 | + self.virtual_network_subnet_usage = VirtualNetworkSubnetUsageOperations( |
| 142 | + self._client, self._config, self._serialize, self._deserialize |
| 143 | + ) |
| 144 | + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) |
| 145 | + self.databases = DatabasesOperations(self._client, self._config, self._serialize, self._deserialize) |
| 146 | + self.get_private_dns_zone_suffix = GetPrivateDnsZoneSuffixOperations( |
| 147 | + self._client, self._config, self._serialize, self._deserialize |
| 148 | + ) |
| 149 | + |
| 150 | + def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: |
| 151 | + """Runs the network request through the client's chained policies. |
| 152 | +
|
| 153 | + >>> from azure.core.rest import HttpRequest |
| 154 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 155 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 156 | + >>> response = client._send_request(request) |
| 157 | + <HttpResponse: 200 OK> |
| 158 | +
|
| 159 | + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| 160 | +
|
| 161 | + :param request: The network request you want to make. Required. |
| 162 | + :type request: ~azure.core.rest.HttpRequest |
| 163 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
| 164 | + :return: The response of your network call. Does not do error handling on your response. |
| 165 | + :rtype: ~azure.core.rest.HttpResponse |
| 166 | + """ |
| 167 | + |
| 168 | + request_copy = deepcopy(request) |
| 169 | + request_copy.url = self._client.format_url(request_copy.url) |
| 170 | + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore |
| 171 | + |
| 172 | + def close(self) -> None: |
| 173 | + self._client.close() |
| 174 | + |
| 175 | + def __enter__(self) -> Self: |
| 176 | + self._client.__enter__() |
| 177 | + return self |
| 178 | + |
| 179 | + def __exit__(self, *exc_details: Any) -> None: |
| 180 | + self._client.__exit__(*exc_details) |
0 commit comments