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.pipeline import PipelineResponse
13from azure.core.pipeline.transport import HttpRequest, HttpResponse
14from azure.mgmt.core.exceptions import ARMErrorFormat
15
16from .. import models as _models
17
18if TYPE_CHECKING:
19    # pylint: disable=unused-import,ungrouped-imports
20    from typing import Any, Callable, Dict, Generic, Optional, TypeVar
21
22    T = TypeVar('T')
23    ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
24
25class ServiceTagsOperations(object):
26    """ServiceTagsOperations operations.
27
28    You should not instantiate this class directly. Instead, you should create a Client instance that
29    instantiates it for you and attaches it as an attribute.
30
31    :ivar models: Alias to model classes used in this operation group.
32    :type models: ~azure.mgmt.network.v2019_11_01.models
33    :param client: Client for service requests.
34    :param config: Configuration of service client.
35    :param serializer: An object model serializer.
36    :param deserializer: An object model deserializer.
37    """
38
39    models = _models
40
41    def __init__(self, client, config, serializer, deserializer):
42        self._client = client
43        self._serialize = serializer
44        self._deserialize = deserializer
45        self._config = config
46
47    def list(
48        self,
49        location,  # type: str
50        **kwargs  # type: Any
51    ):
52        # type: (...) -> "_models.ServiceTagsListResult"
53        """Gets a list of service tag information resources.
54
55        :param location: The location that will be used as a reference for version (not as a filter
56         based on location, you will get the list of service tags with prefix details across all regions
57         but limited to the cloud that your subscription belongs to).
58        :type location: str
59        :keyword callable cls: A custom type or function that will be passed the direct response
60        :return: ServiceTagsListResult, or the result of cls(response)
61        :rtype: ~azure.mgmt.network.v2019_11_01.models.ServiceTagsListResult
62        :raises: ~azure.core.exceptions.HttpResponseError
63        """
64        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ServiceTagsListResult"]
65        error_map = {
66            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
67        }
68        error_map.update(kwargs.pop('error_map', {}))
69        api_version = "2019-11-01"
70        accept = "application/json"
71
72        # Construct URL
73        url = self.list.metadata['url']  # type: ignore
74        path_format_arguments = {
75            'location': self._serialize.url("location", location, 'str'),
76            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
77        }
78        url = self._client.format_url(url, **path_format_arguments)
79
80        # Construct parameters
81        query_parameters = {}  # type: Dict[str, Any]
82        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
83
84        # Construct headers
85        header_parameters = {}  # type: Dict[str, Any]
86        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
87
88        request = self._client.get(url, query_parameters, header_parameters)
89        pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
90        response = pipeline_response.http_response
91
92        if response.status_code not in [200]:
93            map_error(status_code=response.status_code, response=response, error_map=error_map)
94            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
95
96        deserialized = self._deserialize('ServiceTagsListResult', pipeline_response)
97
98        if cls:
99            return cls(pipeline_response, deserialized, {})
100
101        return deserialized
102    list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/serviceTags'}  # type: ignore
103