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 SubscriptionsOperations(object): 27 """SubscriptionsOperations 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.resource.subscriptions.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_locations( 49 self, 50 subscription_id, # type: str 51 **kwargs # type: Any 52 ): 53 # type: (...) -> Iterable["_models.LocationListResult"] 54 """Gets all available geo-locations. 55 56 This operation provides all the locations that are available for resource providers; however, 57 each resource provider may support a subset of this list. 58 59 :param subscription_id: The ID of the target subscription. 60 :type subscription_id: 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 LocationListResult or the result of cls(response) 63 :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.resource.subscriptions.v2019_11_01.models.LocationListResult] 64 :raises: ~azure.core.exceptions.HttpResponseError 65 """ 66 cls = kwargs.pop('cls', None) # type: ClsType["_models.LocationListResult"] 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_locations.metadata['url'] # type: ignore 82 path_format_arguments = { 83 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), 84 } 85 url = self._client.format_url(url, **path_format_arguments) 86 # Construct parameters 87 query_parameters = {} # type: Dict[str, Any] 88 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 89 90 request = self._client.get(url, query_parameters, header_parameters) 91 else: 92 url = next_link 93 query_parameters = {} # type: Dict[str, Any] 94 request = self._client.get(url, query_parameters, header_parameters) 95 return request 96 97 def extract_data(pipeline_response): 98 deserialized = self._deserialize('LocationListResult', pipeline_response) 99 list_of_elem = deserialized.value 100 if cls: 101 list_of_elem = cls(list_of_elem) 102 return None, iter(list_of_elem) 103 104 def get_next(next_link=None): 105 request = prepare_request(next_link) 106 107 pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) 108 response = pipeline_response.http_response 109 110 if response.status_code not in [200]: 111 map_error(status_code=response.status_code, response=response, error_map=error_map) 112 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 113 114 return pipeline_response 115 116 return ItemPaged( 117 get_next, extract_data 118 ) 119 list_locations.metadata = {'url': '/subscriptions/{subscriptionId}/locations'} # type: ignore 120 121 def get( 122 self, 123 subscription_id, # type: str 124 **kwargs # type: Any 125 ): 126 # type: (...) -> "_models.Subscription" 127 """Gets details about a specified subscription. 128 129 :param subscription_id: The ID of the target subscription. 130 :type subscription_id: str 131 :keyword callable cls: A custom type or function that will be passed the direct response 132 :return: Subscription, or the result of cls(response) 133 :rtype: ~azure.mgmt.resource.subscriptions.v2019_11_01.models.Subscription 134 :raises: ~azure.core.exceptions.HttpResponseError 135 """ 136 cls = kwargs.pop('cls', None) # type: ClsType["_models.Subscription"] 137 error_map = { 138 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 139 } 140 error_map.update(kwargs.pop('error_map', {})) 141 api_version = "2019-11-01" 142 accept = "application/json" 143 144 # Construct URL 145 url = self.get.metadata['url'] # type: ignore 146 path_format_arguments = { 147 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), 148 } 149 url = self._client.format_url(url, **path_format_arguments) 150 151 # Construct parameters 152 query_parameters = {} # type: Dict[str, Any] 153 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 154 155 # Construct headers 156 header_parameters = {} # type: Dict[str, Any] 157 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 158 159 request = self._client.get(url, query_parameters, header_parameters) 160 pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) 161 response = pipeline_response.http_response 162 163 if response.status_code not in [200]: 164 map_error(status_code=response.status_code, response=response, error_map=error_map) 165 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 166 167 deserialized = self._deserialize('Subscription', pipeline_response) 168 169 if cls: 170 return cls(pipeline_response, deserialized, {}) 171 172 return deserialized 173 get.metadata = {'url': '/subscriptions/{subscriptionId}'} # type: ignore 174 175 def list( 176 self, 177 **kwargs # type: Any 178 ): 179 # type: (...) -> Iterable["_models.SubscriptionListResult"] 180 """Gets all subscriptions for a tenant. 181 182 :keyword callable cls: A custom type or function that will be passed the direct response 183 :return: An iterator like instance of either SubscriptionListResult or the result of cls(response) 184 :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.resource.subscriptions.v2019_11_01.models.SubscriptionListResult] 185 :raises: ~azure.core.exceptions.HttpResponseError 186 """ 187 cls = kwargs.pop('cls', None) # type: ClsType["_models.SubscriptionListResult"] 188 error_map = { 189 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 190 } 191 error_map.update(kwargs.pop('error_map', {})) 192 api_version = "2019-11-01" 193 accept = "application/json" 194 195 def prepare_request(next_link=None): 196 # Construct headers 197 header_parameters = {} # type: Dict[str, Any] 198 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 199 200 if not next_link: 201 # Construct URL 202 url = self.list.metadata['url'] # type: ignore 203 # Construct parameters 204 query_parameters = {} # type: Dict[str, Any] 205 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 206 207 request = self._client.get(url, query_parameters, header_parameters) 208 else: 209 url = next_link 210 query_parameters = {} # type: Dict[str, Any] 211 request = self._client.get(url, query_parameters, header_parameters) 212 return request 213 214 def extract_data(pipeline_response): 215 deserialized = self._deserialize('SubscriptionListResult', pipeline_response) 216 list_of_elem = deserialized.value 217 if cls: 218 list_of_elem = cls(list_of_elem) 219 return deserialized.next_link or None, iter(list_of_elem) 220 221 def get_next(next_link=None): 222 request = prepare_request(next_link) 223 224 pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) 225 response = pipeline_response.http_response 226 227 if response.status_code not in [200]: 228 map_error(status_code=response.status_code, response=response, error_map=error_map) 229 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 230 231 return pipeline_response 232 233 return ItemPaged( 234 get_next, extract_data 235 ) 236 list.metadata = {'url': '/subscriptions'} # type: ignore 237