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 VpnLinkConnectionsOperations(object):
27    """VpnLinkConnectionsOperations 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_by_vpn_connection(
49        self,
50        resource_group_name,  # type: str
51        gateway_name,  # type: str
52        connection_name,  # type: str
53        **kwargs  # type: Any
54    ):
55        # type: (...) -> Iterable["_models.ListVpnSiteLinkConnectionsResult"]
56        """Retrieves all vpn site link connections for a particular virtual wan vpn gateway vpn
57        connection.
58
59        :param resource_group_name: The resource group name of the VpnGateway.
60        :type resource_group_name: str
61        :param gateway_name: The name of the gateway.
62        :type gateway_name: str
63        :param connection_name: The name of the vpn connection.
64        :type connection_name: str
65        :keyword callable cls: A custom type or function that will be passed the direct response
66        :return: An iterator like instance of either ListVpnSiteLinkConnectionsResult or the result of cls(response)
67        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.network.v2019_11_01.models.ListVpnSiteLinkConnectionsResult]
68        :raises: ~azure.core.exceptions.HttpResponseError
69        """
70        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ListVpnSiteLinkConnectionsResult"]
71        error_map = {
72            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
73        }
74        error_map.update(kwargs.pop('error_map', {}))
75        api_version = "2019-11-01"
76        accept = "application/json"
77
78        def prepare_request(next_link=None):
79            # Construct headers
80            header_parameters = {}  # type: Dict[str, Any]
81            header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
82
83            if not next_link:
84                # Construct URL
85                url = self.list_by_vpn_connection.metadata['url']  # type: ignore
86                path_format_arguments = {
87                    'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
88                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
89                    'gatewayName': self._serialize.url("gateway_name", gateway_name, 'str'),
90                    'connectionName': self._serialize.url("connection_name", connection_name, 'str'),
91                }
92                url = self._client.format_url(url, **path_format_arguments)
93                # Construct parameters
94                query_parameters = {}  # type: Dict[str, Any]
95                query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
96
97                request = self._client.get(url, query_parameters, header_parameters)
98            else:
99                url = next_link
100                query_parameters = {}  # type: Dict[str, Any]
101                request = self._client.get(url, query_parameters, header_parameters)
102            return request
103
104        def extract_data(pipeline_response):
105            deserialized = self._deserialize('ListVpnSiteLinkConnectionsResult', pipeline_response)
106            list_of_elem = deserialized.value
107            if cls:
108                list_of_elem = cls(list_of_elem)
109            return deserialized.next_link or None, iter(list_of_elem)
110
111        def get_next(next_link=None):
112            request = prepare_request(next_link)
113
114            pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
115            response = pipeline_response.http_response
116
117            if response.status_code not in [200]:
118                map_error(status_code=response.status_code, response=response, error_map=error_map)
119                raise HttpResponseError(response=response, error_format=ARMErrorFormat)
120
121            return pipeline_response
122
123        return ItemPaged(
124            get_next, extract_data
125        )
126    list_by_vpn_connection.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections'}  # type: ignore
127