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 Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar, Union 9import warnings 10 11from azure.core.async_paging import AsyncItemPaged, AsyncList 12from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error 13from azure.core.pipeline import PipelineResponse 14from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest 15from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod 16from azure.mgmt.core.exceptions import ARMErrorFormat 17from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling 18 19from ... import models as _models 20 21T = TypeVar('T') 22ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] 23 24class StorageAccountsOperations: 25 """StorageAccountsOperations async operations. 26 27 You should not instantiate this class directly. Instead, you should create a Client instance that 28 instantiates it for you and attaches it as an attribute. 29 30 :ivar models: Alias to model classes used in this operation group. 31 :type models: ~azure.mgmt.storage.v2018_11_01.models 32 :param client: Client for service requests. 33 :param config: Configuration of service client. 34 :param serializer: An object model serializer. 35 :param deserializer: An object model deserializer. 36 """ 37 38 models = _models 39 40 def __init__(self, client, config, serializer, deserializer) -> None: 41 self._client = client 42 self._serialize = serializer 43 self._deserialize = deserializer 44 self._config = config 45 46 async def check_name_availability( 47 self, 48 account_name: "_models.StorageAccountCheckNameAvailabilityParameters", 49 **kwargs: Any 50 ) -> "_models.CheckNameAvailabilityResult": 51 """Checks that the storage account name is valid and is not already in use. 52 53 :param account_name: The name of the storage account within the specified resource group. 54 Storage account names must be between 3 and 24 characters in length and use numbers and 55 lower-case letters only. 56 :type account_name: ~azure.mgmt.storage.v2018_11_01.models.StorageAccountCheckNameAvailabilityParameters 57 :keyword callable cls: A custom type or function that will be passed the direct response 58 :return: CheckNameAvailabilityResult, or the result of cls(response) 59 :rtype: ~azure.mgmt.storage.v2018_11_01.models.CheckNameAvailabilityResult 60 :raises: ~azure.core.exceptions.HttpResponseError 61 """ 62 cls = kwargs.pop('cls', None) # type: ClsType["_models.CheckNameAvailabilityResult"] 63 error_map = { 64 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 65 } 66 error_map.update(kwargs.pop('error_map', {})) 67 api_version = "2018-11-01" 68 content_type = kwargs.pop("content_type", "application/json") 69 accept = "application/json" 70 71 # Construct URL 72 url = self.check_name_availability.metadata['url'] # type: ignore 73 path_format_arguments = { 74 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 75 } 76 url = self._client.format_url(url, **path_format_arguments) 77 78 # Construct parameters 79 query_parameters = {} # type: Dict[str, Any] 80 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 81 82 # Construct headers 83 header_parameters = {} # type: Dict[str, Any] 84 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 85 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 86 87 body_content_kwargs = {} # type: Dict[str, Any] 88 body_content = self._serialize.body(account_name, 'StorageAccountCheckNameAvailabilityParameters') 89 body_content_kwargs['content'] = body_content 90 request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) 91 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 92 response = pipeline_response.http_response 93 94 if response.status_code not in [200]: 95 map_error(status_code=response.status_code, response=response, error_map=error_map) 96 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 97 98 deserialized = self._deserialize('CheckNameAvailabilityResult', pipeline_response) 99 100 if cls: 101 return cls(pipeline_response, deserialized, {}) 102 103 return deserialized 104 check_name_availability.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Storage/checkNameAvailability'} # type: ignore 105 106 async def _create_initial( 107 self, 108 resource_group_name: str, 109 account_name: str, 110 parameters: "_models.StorageAccountCreateParameters", 111 **kwargs: Any 112 ) -> Optional["_models.StorageAccount"]: 113 cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.StorageAccount"]] 114 error_map = { 115 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 116 } 117 error_map.update(kwargs.pop('error_map', {})) 118 api_version = "2018-11-01" 119 content_type = kwargs.pop("content_type", "application/json") 120 accept = "application/json" 121 122 # Construct URL 123 url = self._create_initial.metadata['url'] # type: ignore 124 path_format_arguments = { 125 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 126 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 127 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 128 } 129 url = self._client.format_url(url, **path_format_arguments) 130 131 # Construct parameters 132 query_parameters = {} # type: Dict[str, Any] 133 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 134 135 # Construct headers 136 header_parameters = {} # type: Dict[str, Any] 137 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 138 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 139 140 body_content_kwargs = {} # type: Dict[str, Any] 141 body_content = self._serialize.body(parameters, 'StorageAccountCreateParameters') 142 body_content_kwargs['content'] = body_content 143 request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) 144 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 145 response = pipeline_response.http_response 146 147 if response.status_code not in [200, 202]: 148 map_error(status_code=response.status_code, response=response, error_map=error_map) 149 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 150 151 deserialized = None 152 if response.status_code == 200: 153 deserialized = self._deserialize('StorageAccount', pipeline_response) 154 155 if cls: 156 return cls(pipeline_response, deserialized, {}) 157 158 return deserialized 159 _create_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'} # type: ignore 160 161 async def begin_create( 162 self, 163 resource_group_name: str, 164 account_name: str, 165 parameters: "_models.StorageAccountCreateParameters", 166 **kwargs: Any 167 ) -> AsyncLROPoller["_models.StorageAccount"]: 168 """Asynchronously creates a new storage account with the specified parameters. If an account is 169 already created and a subsequent create request is issued with different properties, the 170 account properties will be updated. If an account is already created and a subsequent create or 171 update request is issued with the exact same set of properties, the request will succeed. 172 173 :param resource_group_name: The name of the resource group within the user's subscription. The 174 name is case insensitive. 175 :type resource_group_name: str 176 :param account_name: The name of the storage account within the specified resource group. 177 Storage account names must be between 3 and 24 characters in length and use numbers and 178 lower-case letters only. 179 :type account_name: str 180 :param parameters: The parameters to provide for the created account. 181 :type parameters: ~azure.mgmt.storage.v2018_11_01.models.StorageAccountCreateParameters 182 :keyword callable cls: A custom type or function that will be passed the direct response 183 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 184 :keyword polling: By default, your polling method will be AsyncARMPolling. 185 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 186 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 187 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 188 :return: An instance of AsyncLROPoller that returns either StorageAccount or the result of cls(response) 189 :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.storage.v2018_11_01.models.StorageAccount] 190 :raises ~azure.core.exceptions.HttpResponseError: 191 """ 192 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 193 cls = kwargs.pop('cls', None) # type: ClsType["_models.StorageAccount"] 194 lro_delay = kwargs.pop( 195 'polling_interval', 196 self._config.polling_interval 197 ) 198 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 199 if cont_token is None: 200 raw_result = await self._create_initial( 201 resource_group_name=resource_group_name, 202 account_name=account_name, 203 parameters=parameters, 204 cls=lambda x,y,z: x, 205 **kwargs 206 ) 207 208 kwargs.pop('error_map', None) 209 kwargs.pop('content_type', None) 210 211 def get_long_running_output(pipeline_response): 212 deserialized = self._deserialize('StorageAccount', pipeline_response) 213 214 if cls: 215 return cls(pipeline_response, deserialized, {}) 216 return deserialized 217 218 path_format_arguments = { 219 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 220 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 221 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 222 } 223 224 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 225 elif polling is False: polling_method = AsyncNoPolling() 226 else: polling_method = polling 227 if cont_token: 228 return AsyncLROPoller.from_continuation_token( 229 polling_method=polling_method, 230 continuation_token=cont_token, 231 client=self._client, 232 deserialization_callback=get_long_running_output 233 ) 234 else: 235 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 236 begin_create.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'} # type: ignore 237 238 async def delete( 239 self, 240 resource_group_name: str, 241 account_name: str, 242 **kwargs: Any 243 ) -> None: 244 """Deletes a storage account in Microsoft Azure. 245 246 :param resource_group_name: The name of the resource group within the user's subscription. The 247 name is case insensitive. 248 :type resource_group_name: str 249 :param account_name: The name of the storage account within the specified resource group. 250 Storage account names must be between 3 and 24 characters in length and use numbers and 251 lower-case letters only. 252 :type account_name: str 253 :keyword callable cls: A custom type or function that will be passed the direct response 254 :return: None, or the result of cls(response) 255 :rtype: None 256 :raises: ~azure.core.exceptions.HttpResponseError 257 """ 258 cls = kwargs.pop('cls', None) # type: ClsType[None] 259 error_map = { 260 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 261 } 262 error_map.update(kwargs.pop('error_map', {})) 263 api_version = "2018-11-01" 264 265 # Construct URL 266 url = self.delete.metadata['url'] # type: ignore 267 path_format_arguments = { 268 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 269 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 270 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 271 } 272 url = self._client.format_url(url, **path_format_arguments) 273 274 # Construct parameters 275 query_parameters = {} # type: Dict[str, Any] 276 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 277 278 # Construct headers 279 header_parameters = {} # type: Dict[str, Any] 280 281 request = self._client.delete(url, query_parameters, header_parameters) 282 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 283 response = pipeline_response.http_response 284 285 if response.status_code not in [200, 204]: 286 map_error(status_code=response.status_code, response=response, error_map=error_map) 287 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 288 289 if cls: 290 return cls(pipeline_response, None, {}) 291 292 delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'} # type: ignore 293 294 async def get_properties( 295 self, 296 resource_group_name: str, 297 account_name: str, 298 expand: Optional[str] = "geoReplicationStats", 299 **kwargs: Any 300 ) -> "_models.StorageAccount": 301 """Returns the properties for the specified storage account including but not limited to name, SKU 302 name, location, and account status. The ListKeys operation should be used to retrieve storage 303 keys. 304 305 :param resource_group_name: The name of the resource group within the user's subscription. The 306 name is case insensitive. 307 :type resource_group_name: str 308 :param account_name: The name of the storage account within the specified resource group. 309 Storage account names must be between 3 and 24 characters in length and use numbers and 310 lower-case letters only. 311 :type account_name: str 312 :param expand: May be used to expand the properties within account's properties. By default, 313 data is not included when fetching properties. Currently we only support geoReplicationStats. 314 :type expand: str 315 :keyword callable cls: A custom type or function that will be passed the direct response 316 :return: StorageAccount, or the result of cls(response) 317 :rtype: ~azure.mgmt.storage.v2018_11_01.models.StorageAccount 318 :raises: ~azure.core.exceptions.HttpResponseError 319 """ 320 cls = kwargs.pop('cls', None) # type: ClsType["_models.StorageAccount"] 321 error_map = { 322 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 323 } 324 error_map.update(kwargs.pop('error_map', {})) 325 api_version = "2018-11-01" 326 accept = "application/json" 327 328 # Construct URL 329 url = self.get_properties.metadata['url'] # type: ignore 330 path_format_arguments = { 331 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 332 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 333 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 334 } 335 url = self._client.format_url(url, **path_format_arguments) 336 337 # Construct parameters 338 query_parameters = {} # type: Dict[str, Any] 339 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 340 if expand is not None: 341 query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') 342 343 # Construct headers 344 header_parameters = {} # type: Dict[str, Any] 345 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 346 347 request = self._client.get(url, query_parameters, header_parameters) 348 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 349 response = pipeline_response.http_response 350 351 if response.status_code not in [200]: 352 map_error(status_code=response.status_code, response=response, error_map=error_map) 353 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 354 355 deserialized = self._deserialize('StorageAccount', pipeline_response) 356 357 if cls: 358 return cls(pipeline_response, deserialized, {}) 359 360 return deserialized 361 get_properties.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'} # type: ignore 362 363 async def update( 364 self, 365 resource_group_name: str, 366 account_name: str, 367 parameters: "_models.StorageAccountUpdateParameters", 368 **kwargs: Any 369 ) -> "_models.StorageAccount": 370 """The update operation can be used to update the SKU, encryption, access tier, or tags for a 371 storage account. It can also be used to map the account to a custom domain. Only one custom 372 domain is supported per storage account; the replacement/change of custom domain is not 373 supported. In order to replace an old custom domain, the old value must be cleared/unregistered 374 before a new value can be set. The update of multiple properties is supported. This call does 375 not change the storage keys for the account. If you want to change the storage account keys, 376 use the regenerate keys operation. The location and name of the storage account cannot be 377 changed after creation. 378 379 :param resource_group_name: The name of the resource group within the user's subscription. The 380 name is case insensitive. 381 :type resource_group_name: str 382 :param account_name: The name of the storage account within the specified resource group. 383 Storage account names must be between 3 and 24 characters in length and use numbers and 384 lower-case letters only. 385 :type account_name: str 386 :param parameters: The parameters to provide for the updated account. 387 :type parameters: ~azure.mgmt.storage.v2018_11_01.models.StorageAccountUpdateParameters 388 :keyword callable cls: A custom type or function that will be passed the direct response 389 :return: StorageAccount, or the result of cls(response) 390 :rtype: ~azure.mgmt.storage.v2018_11_01.models.StorageAccount 391 :raises: ~azure.core.exceptions.HttpResponseError 392 """ 393 cls = kwargs.pop('cls', None) # type: ClsType["_models.StorageAccount"] 394 error_map = { 395 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 396 } 397 error_map.update(kwargs.pop('error_map', {})) 398 api_version = "2018-11-01" 399 content_type = kwargs.pop("content_type", "application/json") 400 accept = "application/json" 401 402 # Construct URL 403 url = self.update.metadata['url'] # type: ignore 404 path_format_arguments = { 405 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 406 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 407 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 408 } 409 url = self._client.format_url(url, **path_format_arguments) 410 411 # Construct parameters 412 query_parameters = {} # type: Dict[str, Any] 413 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 414 415 # Construct headers 416 header_parameters = {} # type: Dict[str, Any] 417 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 418 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 419 420 body_content_kwargs = {} # type: Dict[str, Any] 421 body_content = self._serialize.body(parameters, 'StorageAccountUpdateParameters') 422 body_content_kwargs['content'] = body_content 423 request = self._client.patch(url, query_parameters, header_parameters, **body_content_kwargs) 424 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 425 response = pipeline_response.http_response 426 427 if response.status_code not in [200]: 428 map_error(status_code=response.status_code, response=response, error_map=error_map) 429 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 430 431 deserialized = self._deserialize('StorageAccount', pipeline_response) 432 433 if cls: 434 return cls(pipeline_response, deserialized, {}) 435 436 return deserialized 437 update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}'} # type: ignore 438 439 def list( 440 self, 441 **kwargs: Any 442 ) -> AsyncIterable["_models.StorageAccountListResult"]: 443 """Lists all the storage accounts available under the subscription. Note that storage keys are not 444 returned; use the ListKeys operation for this. 445 446 :keyword callable cls: A custom type or function that will be passed the direct response 447 :return: An iterator like instance of either StorageAccountListResult or the result of cls(response) 448 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.storage.v2018_11_01.models.StorageAccountListResult] 449 :raises: ~azure.core.exceptions.HttpResponseError 450 """ 451 cls = kwargs.pop('cls', None) # type: ClsType["_models.StorageAccountListResult"] 452 error_map = { 453 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 454 } 455 error_map.update(kwargs.pop('error_map', {})) 456 api_version = "2018-11-01" 457 accept = "application/json" 458 459 def prepare_request(next_link=None): 460 # Construct headers 461 header_parameters = {} # type: Dict[str, Any] 462 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 463 464 if not next_link: 465 # Construct URL 466 url = self.list.metadata['url'] # type: ignore 467 path_format_arguments = { 468 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 469 } 470 url = self._client.format_url(url, **path_format_arguments) 471 # Construct parameters 472 query_parameters = {} # type: Dict[str, Any] 473 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 474 475 request = self._client.get(url, query_parameters, header_parameters) 476 else: 477 url = next_link 478 query_parameters = {} # type: Dict[str, Any] 479 request = self._client.get(url, query_parameters, header_parameters) 480 return request 481 482 async def extract_data(pipeline_response): 483 deserialized = self._deserialize('StorageAccountListResult', pipeline_response) 484 list_of_elem = deserialized.value 485 if cls: 486 list_of_elem = cls(list_of_elem) 487 return None, AsyncList(list_of_elem) 488 489 async def get_next(next_link=None): 490 request = prepare_request(next_link) 491 492 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 493 response = pipeline_response.http_response 494 495 if response.status_code not in [200]: 496 map_error(status_code=response.status_code, response=response, error_map=error_map) 497 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 498 499 return pipeline_response 500 501 return AsyncItemPaged( 502 get_next, extract_data 503 ) 504 list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Storage/storageAccounts'} # type: ignore 505 506 def list_by_resource_group( 507 self, 508 resource_group_name: str, 509 **kwargs: Any 510 ) -> AsyncIterable["_models.StorageAccountListResult"]: 511 """Lists all the storage accounts available under the given resource group. Note that storage keys 512 are not returned; use the ListKeys operation for this. 513 514 :param resource_group_name: The name of the resource group within the user's subscription. The 515 name is case insensitive. 516 :type resource_group_name: str 517 :keyword callable cls: A custom type or function that will be passed the direct response 518 :return: An iterator like instance of either StorageAccountListResult or the result of cls(response) 519 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.storage.v2018_11_01.models.StorageAccountListResult] 520 :raises: ~azure.core.exceptions.HttpResponseError 521 """ 522 cls = kwargs.pop('cls', None) # type: ClsType["_models.StorageAccountListResult"] 523 error_map = { 524 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 525 } 526 error_map.update(kwargs.pop('error_map', {})) 527 api_version = "2018-11-01" 528 accept = "application/json" 529 530 def prepare_request(next_link=None): 531 # Construct headers 532 header_parameters = {} # type: Dict[str, Any] 533 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 534 535 if not next_link: 536 # Construct URL 537 url = self.list_by_resource_group.metadata['url'] # type: ignore 538 path_format_arguments = { 539 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 540 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 541 } 542 url = self._client.format_url(url, **path_format_arguments) 543 # Construct parameters 544 query_parameters = {} # type: Dict[str, Any] 545 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 546 547 request = self._client.get(url, query_parameters, header_parameters) 548 else: 549 url = next_link 550 query_parameters = {} # type: Dict[str, Any] 551 request = self._client.get(url, query_parameters, header_parameters) 552 return request 553 554 async def extract_data(pipeline_response): 555 deserialized = self._deserialize('StorageAccountListResult', pipeline_response) 556 list_of_elem = deserialized.value 557 if cls: 558 list_of_elem = cls(list_of_elem) 559 return None, AsyncList(list_of_elem) 560 561 async def get_next(next_link=None): 562 request = prepare_request(next_link) 563 564 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 565 response = pipeline_response.http_response 566 567 if response.status_code not in [200]: 568 map_error(status_code=response.status_code, response=response, error_map=error_map) 569 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 570 571 return pipeline_response 572 573 return AsyncItemPaged( 574 get_next, extract_data 575 ) 576 list_by_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts'} # type: ignore 577 578 async def list_keys( 579 self, 580 resource_group_name: str, 581 account_name: str, 582 **kwargs: Any 583 ) -> "_models.StorageAccountListKeysResult": 584 """Lists the access keys for the specified storage account. 585 586 :param resource_group_name: The name of the resource group within the user's subscription. The 587 name is case insensitive. 588 :type resource_group_name: str 589 :param account_name: The name of the storage account within the specified resource group. 590 Storage account names must be between 3 and 24 characters in length and use numbers and 591 lower-case letters only. 592 :type account_name: str 593 :keyword callable cls: A custom type or function that will be passed the direct response 594 :return: StorageAccountListKeysResult, or the result of cls(response) 595 :rtype: ~azure.mgmt.storage.v2018_11_01.models.StorageAccountListKeysResult 596 :raises: ~azure.core.exceptions.HttpResponseError 597 """ 598 cls = kwargs.pop('cls', None) # type: ClsType["_models.StorageAccountListKeysResult"] 599 error_map = { 600 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 601 } 602 error_map.update(kwargs.pop('error_map', {})) 603 api_version = "2018-11-01" 604 accept = "application/json" 605 606 # Construct URL 607 url = self.list_keys.metadata['url'] # type: ignore 608 path_format_arguments = { 609 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 610 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 611 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 612 } 613 url = self._client.format_url(url, **path_format_arguments) 614 615 # Construct parameters 616 query_parameters = {} # type: Dict[str, Any] 617 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 618 619 # Construct headers 620 header_parameters = {} # type: Dict[str, Any] 621 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 622 623 request = self._client.post(url, query_parameters, header_parameters) 624 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 625 response = pipeline_response.http_response 626 627 if response.status_code not in [200]: 628 map_error(status_code=response.status_code, response=response, error_map=error_map) 629 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 630 631 deserialized = self._deserialize('StorageAccountListKeysResult', pipeline_response) 632 633 if cls: 634 return cls(pipeline_response, deserialized, {}) 635 636 return deserialized 637 list_keys.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/listKeys'} # type: ignore 638 639 async def regenerate_key( 640 self, 641 resource_group_name: str, 642 account_name: str, 643 regenerate_key: "_models.StorageAccountRegenerateKeyParameters", 644 **kwargs: Any 645 ) -> "_models.StorageAccountListKeysResult": 646 """Regenerates one of the access keys for the specified storage account. 647 648 :param resource_group_name: The name of the resource group within the user's subscription. The 649 name is case insensitive. 650 :type resource_group_name: str 651 :param account_name: The name of the storage account within the specified resource group. 652 Storage account names must be between 3 and 24 characters in length and use numbers and 653 lower-case letters only. 654 :type account_name: str 655 :param regenerate_key: Specifies name of the key which should be regenerated -- key1 or key2. 656 :type regenerate_key: ~azure.mgmt.storage.v2018_11_01.models.StorageAccountRegenerateKeyParameters 657 :keyword callable cls: A custom type or function that will be passed the direct response 658 :return: StorageAccountListKeysResult, or the result of cls(response) 659 :rtype: ~azure.mgmt.storage.v2018_11_01.models.StorageAccountListKeysResult 660 :raises: ~azure.core.exceptions.HttpResponseError 661 """ 662 cls = kwargs.pop('cls', None) # type: ClsType["_models.StorageAccountListKeysResult"] 663 error_map = { 664 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 665 } 666 error_map.update(kwargs.pop('error_map', {})) 667 api_version = "2018-11-01" 668 content_type = kwargs.pop("content_type", "application/json") 669 accept = "application/json" 670 671 # Construct URL 672 url = self.regenerate_key.metadata['url'] # type: ignore 673 path_format_arguments = { 674 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 675 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 676 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 677 } 678 url = self._client.format_url(url, **path_format_arguments) 679 680 # Construct parameters 681 query_parameters = {} # type: Dict[str, Any] 682 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 683 684 # Construct headers 685 header_parameters = {} # type: Dict[str, Any] 686 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 687 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 688 689 body_content_kwargs = {} # type: Dict[str, Any] 690 body_content = self._serialize.body(regenerate_key, 'StorageAccountRegenerateKeyParameters') 691 body_content_kwargs['content'] = body_content 692 request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) 693 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 694 response = pipeline_response.http_response 695 696 if response.status_code not in [200]: 697 map_error(status_code=response.status_code, response=response, error_map=error_map) 698 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 699 700 deserialized = self._deserialize('StorageAccountListKeysResult', pipeline_response) 701 702 if cls: 703 return cls(pipeline_response, deserialized, {}) 704 705 return deserialized 706 regenerate_key.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/regenerateKey'} # type: ignore 707 708 async def list_account_sas( 709 self, 710 resource_group_name: str, 711 account_name: str, 712 parameters: "_models.AccountSasParameters", 713 **kwargs: Any 714 ) -> "_models.ListAccountSasResponse": 715 """List SAS credentials of a storage account. 716 717 :param resource_group_name: The name of the resource group within the user's subscription. The 718 name is case insensitive. 719 :type resource_group_name: str 720 :param account_name: The name of the storage account within the specified resource group. 721 Storage account names must be between 3 and 24 characters in length and use numbers and 722 lower-case letters only. 723 :type account_name: str 724 :param parameters: The parameters to provide to list SAS credentials for the storage account. 725 :type parameters: ~azure.mgmt.storage.v2018_11_01.models.AccountSasParameters 726 :keyword callable cls: A custom type or function that will be passed the direct response 727 :return: ListAccountSasResponse, or the result of cls(response) 728 :rtype: ~azure.mgmt.storage.v2018_11_01.models.ListAccountSasResponse 729 :raises: ~azure.core.exceptions.HttpResponseError 730 """ 731 cls = kwargs.pop('cls', None) # type: ClsType["_models.ListAccountSasResponse"] 732 error_map = { 733 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 734 } 735 error_map.update(kwargs.pop('error_map', {})) 736 api_version = "2018-11-01" 737 content_type = kwargs.pop("content_type", "application/json") 738 accept = "application/json" 739 740 # Construct URL 741 url = self.list_account_sas.metadata['url'] # type: ignore 742 path_format_arguments = { 743 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 744 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 745 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 746 } 747 url = self._client.format_url(url, **path_format_arguments) 748 749 # Construct parameters 750 query_parameters = {} # type: Dict[str, Any] 751 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 752 753 # Construct headers 754 header_parameters = {} # type: Dict[str, Any] 755 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 756 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 757 758 body_content_kwargs = {} # type: Dict[str, Any] 759 body_content = self._serialize.body(parameters, 'AccountSasParameters') 760 body_content_kwargs['content'] = body_content 761 request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) 762 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 763 response = pipeline_response.http_response 764 765 if response.status_code not in [200]: 766 map_error(status_code=response.status_code, response=response, error_map=error_map) 767 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 768 769 deserialized = self._deserialize('ListAccountSasResponse', pipeline_response) 770 771 if cls: 772 return cls(pipeline_response, deserialized, {}) 773 774 return deserialized 775 list_account_sas.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/ListAccountSas'} # type: ignore 776 777 async def list_service_sas( 778 self, 779 resource_group_name: str, 780 account_name: str, 781 parameters: "_models.ServiceSasParameters", 782 **kwargs: Any 783 ) -> "_models.ListServiceSasResponse": 784 """List service SAS credentials of a specific resource. 785 786 :param resource_group_name: The name of the resource group within the user's subscription. The 787 name is case insensitive. 788 :type resource_group_name: str 789 :param account_name: The name of the storage account within the specified resource group. 790 Storage account names must be between 3 and 24 characters in length and use numbers and 791 lower-case letters only. 792 :type account_name: str 793 :param parameters: The parameters to provide to list service SAS credentials. 794 :type parameters: ~azure.mgmt.storage.v2018_11_01.models.ServiceSasParameters 795 :keyword callable cls: A custom type or function that will be passed the direct response 796 :return: ListServiceSasResponse, or the result of cls(response) 797 :rtype: ~azure.mgmt.storage.v2018_11_01.models.ListServiceSasResponse 798 :raises: ~azure.core.exceptions.HttpResponseError 799 """ 800 cls = kwargs.pop('cls', None) # type: ClsType["_models.ListServiceSasResponse"] 801 error_map = { 802 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 803 } 804 error_map.update(kwargs.pop('error_map', {})) 805 api_version = "2018-11-01" 806 content_type = kwargs.pop("content_type", "application/json") 807 accept = "application/json" 808 809 # Construct URL 810 url = self.list_service_sas.metadata['url'] # type: ignore 811 path_format_arguments = { 812 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 813 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 814 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 815 } 816 url = self._client.format_url(url, **path_format_arguments) 817 818 # Construct parameters 819 query_parameters = {} # type: Dict[str, Any] 820 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 821 822 # Construct headers 823 header_parameters = {} # type: Dict[str, Any] 824 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 825 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 826 827 body_content_kwargs = {} # type: Dict[str, Any] 828 body_content = self._serialize.body(parameters, 'ServiceSasParameters') 829 body_content_kwargs['content'] = body_content 830 request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) 831 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 832 response = pipeline_response.http_response 833 834 if response.status_code not in [200]: 835 map_error(status_code=response.status_code, response=response, error_map=error_map) 836 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 837 838 deserialized = self._deserialize('ListServiceSasResponse', pipeline_response) 839 840 if cls: 841 return cls(pipeline_response, deserialized, {}) 842 843 return deserialized 844 list_service_sas.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/ListServiceSas'} # type: ignore 845 846 async def _failover_initial( 847 self, 848 resource_group_name: str, 849 account_name: str, 850 **kwargs: Any 851 ) -> None: 852 cls = kwargs.pop('cls', None) # type: ClsType[None] 853 error_map = { 854 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 855 } 856 error_map.update(kwargs.pop('error_map', {})) 857 api_version = "2018-11-01" 858 859 # Construct URL 860 url = self._failover_initial.metadata['url'] # type: ignore 861 path_format_arguments = { 862 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 863 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 864 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 865 } 866 url = self._client.format_url(url, **path_format_arguments) 867 868 # Construct parameters 869 query_parameters = {} # type: Dict[str, Any] 870 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 871 872 # Construct headers 873 header_parameters = {} # type: Dict[str, Any] 874 875 request = self._client.post(url, query_parameters, header_parameters) 876 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 877 response = pipeline_response.http_response 878 879 if response.status_code not in [200, 202]: 880 map_error(status_code=response.status_code, response=response, error_map=error_map) 881 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 882 883 if cls: 884 return cls(pipeline_response, None, {}) 885 886 _failover_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/failover'} # type: ignore 887 888 async def begin_failover( 889 self, 890 resource_group_name: str, 891 account_name: str, 892 **kwargs: Any 893 ) -> AsyncLROPoller[None]: 894 """Failover request can be triggered for a storage account in case of availability issues. The 895 failover occurs from the storage account's primary cluster to secondary cluster for RA-GRS 896 accounts. The secondary cluster will become primary after failover. 897 898 :param resource_group_name: The name of the resource group within the user's subscription. The 899 name is case insensitive. 900 :type resource_group_name: str 901 :param account_name: The name of the storage account within the specified resource group. 902 Storage account names must be between 3 and 24 characters in length and use numbers and 903 lower-case letters only. 904 :type account_name: str 905 :keyword callable cls: A custom type or function that will be passed the direct response 906 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 907 :keyword polling: By default, your polling method will be AsyncARMPolling. 908 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 909 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 910 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 911 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 912 :rtype: ~azure.core.polling.AsyncLROPoller[None] 913 :raises ~azure.core.exceptions.HttpResponseError: 914 """ 915 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 916 cls = kwargs.pop('cls', None) # type: ClsType[None] 917 lro_delay = kwargs.pop( 918 'polling_interval', 919 self._config.polling_interval 920 ) 921 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 922 if cont_token is None: 923 raw_result = await self._failover_initial( 924 resource_group_name=resource_group_name, 925 account_name=account_name, 926 cls=lambda x,y,z: x, 927 **kwargs 928 ) 929 930 kwargs.pop('error_map', None) 931 kwargs.pop('content_type', None) 932 933 def get_long_running_output(pipeline_response): 934 if cls: 935 return cls(pipeline_response, None, {}) 936 937 path_format_arguments = { 938 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 939 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 940 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 941 } 942 943 if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, path_format_arguments=path_format_arguments, **kwargs) 944 elif polling is False: polling_method = AsyncNoPolling() 945 else: polling_method = polling 946 if cont_token: 947 return AsyncLROPoller.from_continuation_token( 948 polling_method=polling_method, 949 continuation_token=cont_token, 950 client=self._client, 951 deserialization_callback=get_long_running_output 952 ) 953 else: 954 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 955 begin_failover.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/failover'} # type: ignore 956 957 async def revoke_user_delegation_keys( 958 self, 959 resource_group_name: str, 960 account_name: str, 961 **kwargs: Any 962 ) -> None: 963 """Revoke user delegation keys. 964 965 :param resource_group_name: The name of the resource group within the user's subscription. The 966 name is case insensitive. 967 :type resource_group_name: str 968 :param account_name: The name of the storage account within the specified resource group. 969 Storage account names must be between 3 and 24 characters in length and use numbers and 970 lower-case letters only. 971 :type account_name: str 972 :keyword callable cls: A custom type or function that will be passed the direct response 973 :return: None, or the result of cls(response) 974 :rtype: None 975 :raises: ~azure.core.exceptions.HttpResponseError 976 """ 977 cls = kwargs.pop('cls', None) # type: ClsType[None] 978 error_map = { 979 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 980 } 981 error_map.update(kwargs.pop('error_map', {})) 982 api_version = "2018-11-01" 983 984 # Construct URL 985 url = self.revoke_user_delegation_keys.metadata['url'] # type: ignore 986 path_format_arguments = { 987 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'), 988 'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3), 989 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1), 990 } 991 url = self._client.format_url(url, **path_format_arguments) 992 993 # Construct parameters 994 query_parameters = {} # type: Dict[str, Any] 995 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 996 997 # Construct headers 998 header_parameters = {} # type: Dict[str, Any] 999 1000 request = self._client.post(url, query_parameters, header_parameters) 1001 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1002 response = pipeline_response.http_response 1003 1004 if response.status_code not in [200]: 1005 map_error(status_code=response.status_code, response=response, error_map=error_map) 1006 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1007 1008 if cls: 1009 return cls(pipeline_response, None, {}) 1010 1011 revoke_user_delegation_keys.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/revokeUserDelegationKeys'} # type: ignore 1012