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
9from typing import Any, Optional, TYPE_CHECKING
10
11from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
12from azure.mgmt.core import AsyncARMPipelineClient
13from msrest import Deserializer, Serializer
14
15if TYPE_CHECKING:
16    # pylint: disable=unused-import,ungrouped-imports
17    from azure.core.credentials_async import AsyncTokenCredential
18
19from ._configuration import ResourceManagementClientConfiguration
20from .operations import DeploymentsOperations
21from .operations import ProvidersOperations
22from .operations import ResourceGroupsOperations
23from .operations import ResourcesOperations
24from .operations import TagsOperations
25from .operations import DeploymentOperationsOperations
26from .. import models
27
28
29class ResourceManagementClient(object):
30    """ResourceManagementClient.
31
32    :ivar deployments: DeploymentsOperations operations
33    :vartype deployments: azure.mgmt.resource.resources.v2016_02_01.aio.operations.DeploymentsOperations
34    :ivar providers: ProvidersOperations operations
35    :vartype providers: azure.mgmt.resource.resources.v2016_02_01.aio.operations.ProvidersOperations
36    :ivar resource_groups: ResourceGroupsOperations operations
37    :vartype resource_groups: azure.mgmt.resource.resources.v2016_02_01.aio.operations.ResourceGroupsOperations
38    :ivar resources: ResourcesOperations operations
39    :vartype resources: azure.mgmt.resource.resources.v2016_02_01.aio.operations.ResourcesOperations
40    :ivar tags: TagsOperations operations
41    :vartype tags: azure.mgmt.resource.resources.v2016_02_01.aio.operations.TagsOperations
42    :ivar deployment_operations: DeploymentOperationsOperations operations
43    :vartype deployment_operations: azure.mgmt.resource.resources.v2016_02_01.aio.operations.DeploymentOperationsOperations
44    :param credential: Credential needed for the client to connect to Azure.
45    :type credential: ~azure.core.credentials_async.AsyncTokenCredential
46    :param subscription_id: The ID of the target subscription.
47    :type subscription_id: str
48    :param str base_url: Service URL
49    :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
50    """
51
52    def __init__(
53        self,
54        credential: "AsyncTokenCredential",
55        subscription_id: str,
56        base_url: Optional[str] = None,
57        **kwargs: Any
58    ) -> None:
59        if not base_url:
60            base_url = 'https://management.azure.com'
61        self._config = ResourceManagementClientConfiguration(credential, subscription_id, **kwargs)
62        self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs)
63
64        client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
65        self._serialize = Serializer(client_models)
66        self._serialize.client_side_validation = False
67        self._deserialize = Deserializer(client_models)
68
69        self.deployments = DeploymentsOperations(
70            self._client, self._config, self._serialize, self._deserialize)
71        self.providers = ProvidersOperations(
72            self._client, self._config, self._serialize, self._deserialize)
73        self.resource_groups = ResourceGroupsOperations(
74            self._client, self._config, self._serialize, self._deserialize)
75        self.resources = ResourcesOperations(
76            self._client, self._config, self._serialize, self._deserialize)
77        self.tags = TagsOperations(
78            self._client, self._config, self._serialize, self._deserialize)
79        self.deployment_operations = DeploymentOperationsOperations(
80            self._client, self._config, self._serialize, self._deserialize)
81
82    async def _send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse:
83        """Runs the network request through the client's chained policies.
84
85        :param http_request: The network request you want to make. Required.
86        :type http_request: ~azure.core.pipeline.transport.HttpRequest
87        :keyword bool stream: Whether the response payload will be streamed. Defaults to True.
88        :return: The response of your network call. Does not do error handling on your response.
89        :rtype: ~azure.core.pipeline.transport.AsyncHttpResponse
90        """
91        path_format_arguments = {
92            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
93        }
94        http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
95        stream = kwargs.pop("stream", True)
96        pipeline_response = await self._client._pipeline.run(http_request, stream=stream, **kwargs)
97        return pipeline_response.http_response
98
99    async def close(self) -> None:
100        await self._client.close()
101
102    async def __aenter__(self) -> "ResourceManagementClient":
103        await self._client.__aenter__()
104        return self
105
106    async def __aexit__(self, *exc_details) -> None:
107        await self._client.__aexit__(*exc_details)
108