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# --------------------------------------------------------------------------
8from typing import TYPE_CHECKING
9import warnings
10
11from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
12from azure.core.paging import ItemPaged
13from azure.core.pipeline import PipelineResponse
14from azure.core.pipeline.transport import HttpRequest, HttpResponse
15from azure.mgmt.core.exceptions import ARMErrorFormat
16
17from .. import models as _models
18
19if TYPE_CHECKING:
20    # pylint: disable=unused-import,ungrouped-imports
21    from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar
22
23    T = TypeVar('T')
24    ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
25
26class AvailableResourceGroupDelegationsOperations(object):
27    """AvailableResourceGroupDelegationsOperations operations.
28
29    You should not instantiate this class directly. Instead, you should create a Client instance that
30    instantiates it for you and attaches it as an attribute.
31
32    :ivar models: Alias to model classes used in this operation group.
33    :type models: ~azure.mgmt.network.v2019_11_01.models
34    :param client: Client for service requests.
35    :param config: Configuration of service client.
36    :param serializer: An object model serializer.
37    :param deserializer: An object model deserializer.
38    """
39
40    models = _models
41
42    def __init__(self, client, config, serializer, deserializer):
43        self._client = client
44        self._serialize = serializer
45        self._deserialize = deserializer
46        self._config = config
47
48    def list(
49        self,
50        location,  # type: str
51        resource_group_name,  # type: str
52        **kwargs  # type: Any
53    ):
54        # type: (...) -> Iterable["_models.AvailableDelegationsResult"]
55        """Gets all of the available subnet delegations for this resource group in this region.
56
57        :param location: The location of the domain name.
58        :type location: str
59        :param resource_group_name: The name of the resource group.
60        :type resource_group_name: str
61        :keyword callable cls: A custom type or function that will be passed the direct response
62        :return: An iterator like instance of either AvailableDelegationsResult or the result of cls(response)
63        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.network.v2019_11_01.models.AvailableDelegationsResult]
64        :raises: ~azure.core.exceptions.HttpResponseError
65        """
66        cls = kwargs.pop('cls', None)  # type: ClsType["_models.AvailableDelegationsResult"]
67        error_map = {
68            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
69        }
70        error_map.update(kwargs.pop('error_map', {}))
71        api_version = "2019-11-01"
72        accept = "application/json"
73
74        def prepare_request(next_link=None):
75            # Construct headers
76            header_parameters = {}  # type: Dict[str, Any]
77            header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
78
79            if not next_link:
80                # Construct URL
81                url = self.list.metadata['url']  # type: ignore
82                path_format_arguments = {
83                    'location': self._serialize.url("location", location, 'str'),
84                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
85                    'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
86                }
87                url = self._client.format_url(url, **path_format_arguments)
88                # Construct parameters
89                query_parameters = {}  # type: Dict[str, Any]
90                query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
91
92                request = self._client.get(url, query_parameters, header_parameters)
93            else:
94                url = next_link
95                query_parameters = {}  # type: Dict[str, Any]
96                request = self._client.get(url, query_parameters, header_parameters)
97            return request
98
99        def extract_data(pipeline_response):
100            deserialized = self._deserialize('AvailableDelegationsResult', pipeline_response)
101            list_of_elem = deserialized.value
102            if cls:
103                list_of_elem = cls(list_of_elem)
104            return deserialized.next_link or None, iter(list_of_elem)
105
106        def get_next(next_link=None):
107            request = prepare_request(next_link)
108
109            pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
110            response = pipeline_response.http_response
111
112            if response.status_code not in [200]:
113                map_error(status_code=response.status_code, response=response, error_map=error_map)
114                raise HttpResponseError(response=response, error_format=ARMErrorFormat)
115
116            return pipeline_response
117
118        return ItemPaged(
119            get_next, extract_data
120        )
121    list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/locations/{location}/availableDelegations'}  # type: ignore
122