|
|
@ -54,6 +54,7 @@ options:
|
|
|
|
- StandardSSD_LRS
|
|
|
|
- StandardSSD_LRS
|
|
|
|
- Standard_RAGRS
|
|
|
|
- Standard_RAGRS
|
|
|
|
- Standard_ZRS
|
|
|
|
- Standard_ZRS
|
|
|
|
|
|
|
|
- Premium_ZRS
|
|
|
|
aliases:
|
|
|
|
aliases:
|
|
|
|
- type
|
|
|
|
- type
|
|
|
|
custom_domain:
|
|
|
|
custom_domain:
|
|
|
@ -62,6 +63,8 @@ options:
|
|
|
|
keys where 'name' is the CNAME source. Only one custom domain is supported per storage account at this
|
|
|
|
keys where 'name' is the CNAME source. Only one custom domain is supported per storage account at this
|
|
|
|
time. To clear the existing custom domain, use an empty string for the custom domain name property.
|
|
|
|
time. To clear the existing custom domain, use an empty string for the custom domain name property.
|
|
|
|
- Can be added to an existing storage account. Will be ignored during storage account creation.
|
|
|
|
- Can be added to an existing storage account. Will be ignored during storage account creation.
|
|
|
|
|
|
|
|
aliases:
|
|
|
|
|
|
|
|
- custom_dns_domain_suffix
|
|
|
|
kind:
|
|
|
|
kind:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The 'kind' of storage.
|
|
|
|
- The 'kind' of storage.
|
|
|
@ -78,10 +81,51 @@ options:
|
|
|
|
- Hot
|
|
|
|
- Hot
|
|
|
|
- Cool
|
|
|
|
- Cool
|
|
|
|
version_added: "2.4"
|
|
|
|
version_added: "2.4"
|
|
|
|
force:
|
|
|
|
force_delete_nonempty:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Attempt deletion if resource already exists and cannot be updated
|
|
|
|
- Attempt deletion if resource already exists and cannot be updated
|
|
|
|
type: bool
|
|
|
|
type: bool
|
|
|
|
|
|
|
|
aliases:
|
|
|
|
|
|
|
|
- force
|
|
|
|
|
|
|
|
https_only:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Allows https traffic only to storage service if sets to true.
|
|
|
|
|
|
|
|
type: bool
|
|
|
|
|
|
|
|
version_added: "2.8"
|
|
|
|
|
|
|
|
blob_cors:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Specifies CORS rules for the Blob service.
|
|
|
|
|
|
|
|
- You can include up to five CorsRule elements in the request.
|
|
|
|
|
|
|
|
- If no blob_cors elements are included in the argument list, nothing about CORS will be changed.
|
|
|
|
|
|
|
|
- "If you want to delete all CORS rules and disable CORS for the Blob service, explicitly set blob_cors: []."
|
|
|
|
|
|
|
|
type: list
|
|
|
|
|
|
|
|
version_added: "2.8"
|
|
|
|
|
|
|
|
suboptions:
|
|
|
|
|
|
|
|
allowed_origins:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- A list of origin domains that will be allowed via CORS, or "*" to allow all domains.
|
|
|
|
|
|
|
|
type: list
|
|
|
|
|
|
|
|
required: true
|
|
|
|
|
|
|
|
allowed_methods:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- A list of HTTP methods that are allowed to be executed by the origin.
|
|
|
|
|
|
|
|
type: list
|
|
|
|
|
|
|
|
required: true
|
|
|
|
|
|
|
|
max_age_in_seconds:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- The number of seconds that the client/browser should cache a preflight response.
|
|
|
|
|
|
|
|
type: int
|
|
|
|
|
|
|
|
required: true
|
|
|
|
|
|
|
|
exposed_headers:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- A list of response headers to expose to CORS clients.
|
|
|
|
|
|
|
|
type: list
|
|
|
|
|
|
|
|
required: true
|
|
|
|
|
|
|
|
allowed_headers:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- A list of headers allowed to be part of the cross-origin request.
|
|
|
|
|
|
|
|
type: list
|
|
|
|
|
|
|
|
required: true
|
|
|
|
|
|
|
|
|
|
|
|
extends_documentation_fragment:
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- azure
|
|
|
|
- azure
|
|
|
@ -90,7 +134,6 @@ extends_documentation_fragment:
|
|
|
|
author:
|
|
|
|
author:
|
|
|
|
- "Chris Houseknecht (@chouseknecht)"
|
|
|
|
- "Chris Houseknecht (@chouseknecht)"
|
|
|
|
- "Matt Davis (@nitzmahone)"
|
|
|
|
- "Matt Davis (@nitzmahone)"
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
EXAMPLES = '''
|
|
|
@ -108,6 +151,25 @@ EXAMPLES = '''
|
|
|
|
tags:
|
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
testing: testing
|
|
|
|
delete: on-exit
|
|
|
|
delete: on-exit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: create an account with blob CORS
|
|
|
|
|
|
|
|
azure_rm_storageaccount:
|
|
|
|
|
|
|
|
resource_group: Testing
|
|
|
|
|
|
|
|
name: clh002
|
|
|
|
|
|
|
|
type: Standard_RAGRS
|
|
|
|
|
|
|
|
blob_cors:
|
|
|
|
|
|
|
|
- allowed_origins:
|
|
|
|
|
|
|
|
- http://www.example.com/
|
|
|
|
|
|
|
|
allowed_methods:
|
|
|
|
|
|
|
|
- GET
|
|
|
|
|
|
|
|
- POST
|
|
|
|
|
|
|
|
allowed_headers:
|
|
|
|
|
|
|
|
- x-ms-meta-data*
|
|
|
|
|
|
|
|
- x-ms-meta-target*
|
|
|
|
|
|
|
|
- x-ms-meta-abc
|
|
|
|
|
|
|
|
exposed_headers:
|
|
|
|
|
|
|
|
- x-ms-meta-*
|
|
|
|
|
|
|
|
max_age_in_seconds: 200
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -151,7 +213,36 @@ except ImportError:
|
|
|
|
# This is handled in azure_rm_common
|
|
|
|
# This is handled in azure_rm_common
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.azure_rm_common import AZURE_SUCCESS_STATE, AzureRMModuleBase, HAS_AZURE
|
|
|
|
import copy
|
|
|
|
|
|
|
|
from ansible.module_utils.azure_rm_common import AZURE_SUCCESS_STATE, AzureRMModuleBase
|
|
|
|
|
|
|
|
from ansible.module_utils._text import to_native
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cors_rule_spec = dict(
|
|
|
|
|
|
|
|
allowed_origins=dict(type='list', elements='str', required=True),
|
|
|
|
|
|
|
|
allowed_methods=dict(type='list', elements='str', required=True),
|
|
|
|
|
|
|
|
max_age_in_seconds=dict(type='int', required=True),
|
|
|
|
|
|
|
|
exposed_headers=dict(type='list', elements='str', required=True),
|
|
|
|
|
|
|
|
allowed_headers=dict(type='list', elements='str', required=True),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def compare_cors(cors1, cors2):
|
|
|
|
|
|
|
|
if len(cors1) != len(cors2):
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
copy2 = copy.copy(cors2)
|
|
|
|
|
|
|
|
for rule1 in cors1:
|
|
|
|
|
|
|
|
matched = False
|
|
|
|
|
|
|
|
for rule2 in copy2:
|
|
|
|
|
|
|
|
if (rule1['max_age_in_seconds'] == rule2['max_age_in_seconds']
|
|
|
|
|
|
|
|
and set(rule1['allowed_methods']) == set(rule2['allowed_methods'])
|
|
|
|
|
|
|
|
and set(rule1['allowed_origins']) == set(rule2['allowed_origins'])
|
|
|
|
|
|
|
|
and set(rule1['allowed_headers']) == set(rule2['allowed_headers'])
|
|
|
|
|
|
|
|
and set(rule1['exposed_headers']) == set(rule2['exposed_headers'])):
|
|
|
|
|
|
|
|
matched = True
|
|
|
|
|
|
|
|
copy2.remove(rule2)
|
|
|
|
|
|
|
|
if not matched:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
@ -159,24 +250,22 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
def __init__(self):
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
|
|
|
|
self.module_arg_spec = dict(
|
|
|
|
self.module_arg_spec = dict(
|
|
|
|
account_type=dict(type='str', choices=['Premium_LRS', 'Standard_GRS', 'Standard_LRS', 'StandardSSD_LRS', 'Standard_RAGRS', 'Standard_ZRS'],
|
|
|
|
account_type=dict(type='str',
|
|
|
|
|
|
|
|
choices=['Premium_LRS', 'Standard_GRS', 'Standard_LRS', 'StandardSSD_LRS', 'Standard_RAGRS', 'Standard_ZRS', 'Premium_ZRS'],
|
|
|
|
aliases=['type']),
|
|
|
|
aliases=['type']),
|
|
|
|
custom_domain=dict(type='dict'),
|
|
|
|
custom_domain=dict(type='dict', aliases=['custom_dns_domain_suffix']),
|
|
|
|
location=dict(type='str'),
|
|
|
|
location=dict(type='str'),
|
|
|
|
name=dict(type='str', required=True),
|
|
|
|
name=dict(type='str', required=True),
|
|
|
|
resource_group=dict(required=True, type='str', aliases=['resource_group_name']),
|
|
|
|
resource_group=dict(required=True, type='str', aliases=['resource_group_name']),
|
|
|
|
state=dict(default='present', choices=['present', 'absent']),
|
|
|
|
state=dict(default='present', choices=['present', 'absent']),
|
|
|
|
force=dict(type='bool', default=False),
|
|
|
|
force_delete_nonempty=dict(type='bool', default=False, aliases=['force']),
|
|
|
|
tags=dict(type='dict'),
|
|
|
|
tags=dict(type='dict'),
|
|
|
|
kind=dict(type='str', default='Storage', choices=['Storage', 'StorageV2', 'BlobStorage']),
|
|
|
|
kind=dict(type='str', default='Storage', choices=['Storage', 'StorageV2', 'BlobStorage']),
|
|
|
|
access_tier=dict(type='str', choices=['Hot', 'Cool'])
|
|
|
|
access_tier=dict(type='str', choices=['Hot', 'Cool']),
|
|
|
|
|
|
|
|
https_only=dict(type='bool', default=False),
|
|
|
|
|
|
|
|
blob_cors=dict(type='list', options=cors_rule_spec, elements='dict')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if HAS_AZURE:
|
|
|
|
|
|
|
|
for key in self.storage_models.SkuName:
|
|
|
|
|
|
|
|
if getattr(key, 'value') not in self.module_arg_spec['account_type']['choices']:
|
|
|
|
|
|
|
|
self.module_arg_spec['account_type']['choices'].append(getattr(key, 'value'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.results = dict(
|
|
|
|
self.results = dict(
|
|
|
|
changed=False,
|
|
|
|
changed=False,
|
|
|
|
state=dict()
|
|
|
|
state=dict()
|
|
|
@ -190,9 +279,11 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
self.account_type = None
|
|
|
|
self.account_type = None
|
|
|
|
self.custom_domain = None
|
|
|
|
self.custom_domain = None
|
|
|
|
self.tags = None
|
|
|
|
self.tags = None
|
|
|
|
self.force = None
|
|
|
|
self.force_delete_nonempty = None
|
|
|
|
self.kind = None
|
|
|
|
self.kind = None
|
|
|
|
self.access_tier = None
|
|
|
|
self.access_tier = None
|
|
|
|
|
|
|
|
self.https_only = None
|
|
|
|
|
|
|
|
self.blob_cors = None
|
|
|
|
|
|
|
|
|
|
|
|
super(AzureRMStorageAccount, self).__init__(self.module_arg_spec,
|
|
|
|
super(AzureRMStorageAccount, self).__init__(self.module_arg_spec,
|
|
|
|
supports_check_mode=True)
|
|
|
|
supports_check_mode=True)
|
|
|
@ -254,19 +345,21 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
def get_account(self):
|
|
|
|
def get_account(self):
|
|
|
|
self.log('Get properties for account {0}'.format(self.name))
|
|
|
|
self.log('Get properties for account {0}'.format(self.name))
|
|
|
|
account_obj = None
|
|
|
|
account_obj = None
|
|
|
|
|
|
|
|
blob_service_props = None
|
|
|
|
account_dict = None
|
|
|
|
account_dict = None
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
account_obj = self.storage_client.storage_accounts.get_properties(self.resource_group, self.name)
|
|
|
|
account_obj = self.storage_client.storage_accounts.get_properties(self.resource_group, self.name)
|
|
|
|
|
|
|
|
blob_service_props = self.storage_client.blob_services.get_service_properties(self.resource_group, self.name)
|
|
|
|
except CloudError:
|
|
|
|
except CloudError:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if account_obj:
|
|
|
|
if account_obj:
|
|
|
|
account_dict = self.account_obj_to_dict(account_obj)
|
|
|
|
account_dict = self.account_obj_to_dict(account_obj, blob_service_props)
|
|
|
|
|
|
|
|
|
|
|
|
return account_dict
|
|
|
|
return account_dict
|
|
|
|
|
|
|
|
|
|
|
|
def account_obj_to_dict(self, account_obj):
|
|
|
|
def account_obj_to_dict(self, account_obj, blob_service_props=None):
|
|
|
|
account_dict = dict(
|
|
|
|
account_dict = dict(
|
|
|
|
id=account_obj.id,
|
|
|
|
id=account_obj.id,
|
|
|
|
name=account_obj.name,
|
|
|
|
name=account_obj.name,
|
|
|
@ -283,7 +376,8 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
if account_obj.status_of_primary is not None else None),
|
|
|
|
if account_obj.status_of_primary is not None else None),
|
|
|
|
status_of_secondary=(account_obj.status_of_secondary.value
|
|
|
|
status_of_secondary=(account_obj.status_of_secondary.value
|
|
|
|
if account_obj.status_of_secondary is not None else None),
|
|
|
|
if account_obj.status_of_secondary is not None else None),
|
|
|
|
primary_location=account_obj.primary_location
|
|
|
|
primary_location=account_obj.primary_location,
|
|
|
|
|
|
|
|
https_only=account_obj.enable_https_traffic_only
|
|
|
|
)
|
|
|
|
)
|
|
|
|
account_dict['custom_domain'] = None
|
|
|
|
account_dict['custom_domain'] = None
|
|
|
|
if account_obj.custom_domain:
|
|
|
|
if account_obj.custom_domain:
|
|
|
@ -309,10 +403,30 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
account_dict['tags'] = None
|
|
|
|
account_dict['tags'] = None
|
|
|
|
if account_obj.tags:
|
|
|
|
if account_obj.tags:
|
|
|
|
account_dict['tags'] = account_obj.tags
|
|
|
|
account_dict['tags'] = account_obj.tags
|
|
|
|
|
|
|
|
if blob_service_props and blob_service_props.cors and blob_service_props.cors.cors_rules:
|
|
|
|
|
|
|
|
account_dict['blob_cors'] = [dict(
|
|
|
|
|
|
|
|
allowed_origins=[to_native(y) for y in x.allowed_origins],
|
|
|
|
|
|
|
|
allowed_methods=[to_native(y) for y in x.allowed_methods],
|
|
|
|
|
|
|
|
max_age_in_seconds=x.max_age_in_seconds,
|
|
|
|
|
|
|
|
exposed_headers=[to_native(y) for y in x.exposed_headers],
|
|
|
|
|
|
|
|
allowed_headers=[to_native(y) for y in x.allowed_headers]
|
|
|
|
|
|
|
|
) for x in blob_service_props.cors.cors_rules]
|
|
|
|
return account_dict
|
|
|
|
return account_dict
|
|
|
|
|
|
|
|
|
|
|
|
def update_account(self):
|
|
|
|
def update_account(self):
|
|
|
|
self.log('Update storage account {0}'.format(self.name))
|
|
|
|
self.log('Update storage account {0}'.format(self.name))
|
|
|
|
|
|
|
|
if bool(self.https_only) != bool(self.account_dict.get('https_only')):
|
|
|
|
|
|
|
|
self.results['changed'] = True
|
|
|
|
|
|
|
|
self.account_dict['https_only'] = self.https_only
|
|
|
|
|
|
|
|
if not self.check_mode:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
parameters = self.storage_models.StorageAccountUpdateParameters(enable_https_traffic_only=self.https_only)
|
|
|
|
|
|
|
|
self.storage_client.storage_accounts.update(self.resource_group,
|
|
|
|
|
|
|
|
self.name,
|
|
|
|
|
|
|
|
parameters)
|
|
|
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
|
|
|
self.fail("Failed to update account type: {0}".format(str(exc)))
|
|
|
|
|
|
|
|
|
|
|
|
if self.account_type:
|
|
|
|
if self.account_type:
|
|
|
|
if self.account_type != self.account_dict['sku_name']:
|
|
|
|
if self.account_type != self.account_dict['sku_name']:
|
|
|
|
# change the account type
|
|
|
|
# change the account type
|
|
|
@ -332,7 +446,7 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.log("sku_name: %s" % self.account_dict['sku_name'])
|
|
|
|
self.log("sku_name: %s" % self.account_dict['sku_name'])
|
|
|
|
self.log("sku_tier: %s" % self.account_dict['sku_tier'])
|
|
|
|
self.log("sku_tier: %s" % self.account_dict['sku_tier'])
|
|
|
|
sku = self.storage_models.Sku(SkuName(self.account_dict['sku_name']))
|
|
|
|
sku = self.storage_models.Sku(name=SkuName(self.account_dict['sku_name']))
|
|
|
|
sku.tier = self.storage_models.SkuTier(self.account_dict['sku_tier'])
|
|
|
|
sku.tier = self.storage_models.SkuTier(self.account_dict['sku_tier'])
|
|
|
|
parameters = self.storage_models.StorageAccountUpdateParameters(sku=sku)
|
|
|
|
parameters = self.storage_models.StorageAccountUpdateParameters(sku=sku)
|
|
|
|
self.storage_client.storage_accounts.update(self.resource_group,
|
|
|
|
self.storage_client.storage_accounts.update(self.resource_group,
|
|
|
@ -377,6 +491,11 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
except Exception as exc:
|
|
|
|
except Exception as exc:
|
|
|
|
self.fail("Failed to update tags: {0}".format(str(exc)))
|
|
|
|
self.fail("Failed to update tags: {0}".format(str(exc)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.blob_cors and not compare_cors(self.account_dict.get('blob_cors', []), self.blob_cors):
|
|
|
|
|
|
|
|
self.results['changed'] = True
|
|
|
|
|
|
|
|
if not self.check_mode:
|
|
|
|
|
|
|
|
self.set_blob_cors()
|
|
|
|
|
|
|
|
|
|
|
|
def create_account(self):
|
|
|
|
def create_account(self):
|
|
|
|
self.log("Creating account {0}".format(self.name))
|
|
|
|
self.log("Creating account {0}".format(self.name))
|
|
|
|
|
|
|
|
|
|
|
@ -398,16 +517,22 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
account_type=self.account_type,
|
|
|
|
account_type=self.account_type,
|
|
|
|
name=self.name,
|
|
|
|
name=self.name,
|
|
|
|
resource_group=self.resource_group,
|
|
|
|
resource_group=self.resource_group,
|
|
|
|
|
|
|
|
enable_https_traffic_only=self.https_only,
|
|
|
|
tags=dict()
|
|
|
|
tags=dict()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if self.tags:
|
|
|
|
if self.tags:
|
|
|
|
account_dict['tags'] = self.tags
|
|
|
|
account_dict['tags'] = self.tags
|
|
|
|
|
|
|
|
if self.blob_cors:
|
|
|
|
|
|
|
|
account_dict['blob_cors'] = self.blob_cors
|
|
|
|
return account_dict
|
|
|
|
return account_dict
|
|
|
|
sku = self.storage_models.Sku(self.storage_models.SkuName(self.account_type))
|
|
|
|
sku = self.storage_models.Sku(name=self.storage_models.SkuName(self.account_type))
|
|
|
|
sku.tier = self.storage_models.SkuTier.standard if 'Standard' in self.account_type else \
|
|
|
|
sku.tier = self.storage_models.SkuTier.standard if 'Standard' in self.account_type else \
|
|
|
|
self.storage_models.SkuTier.premium
|
|
|
|
self.storage_models.SkuTier.premium
|
|
|
|
parameters = self.storage_models.StorageAccountCreateParameters(sku, self.kind, self.location,
|
|
|
|
parameters = self.storage_models.StorageAccountCreateParameters(sku=sku,
|
|
|
|
tags=self.tags, access_tier=self.access_tier)
|
|
|
|
kind=self.kind,
|
|
|
|
|
|
|
|
location=self.location,
|
|
|
|
|
|
|
|
tags=self.tags,
|
|
|
|
|
|
|
|
access_tier=self.access_tier)
|
|
|
|
self.log(str(parameters))
|
|
|
|
self.log(str(parameters))
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
poller = self.storage_client.storage_accounts.create(self.resource_group, self.name, parameters)
|
|
|
|
poller = self.storage_client.storage_accounts.create(self.resource_group, self.name, parameters)
|
|
|
@ -415,13 +540,15 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
except CloudError as e:
|
|
|
|
except CloudError as e:
|
|
|
|
self.log('Error creating storage account.')
|
|
|
|
self.log('Error creating storage account.')
|
|
|
|
self.fail("Failed to create account: {0}".format(str(e)))
|
|
|
|
self.fail("Failed to create account: {0}".format(str(e)))
|
|
|
|
|
|
|
|
if self.blob_cors:
|
|
|
|
|
|
|
|
self.set_blob_cors()
|
|
|
|
# the poller doesn't actually return anything
|
|
|
|
# the poller doesn't actually return anything
|
|
|
|
return self.get_account()
|
|
|
|
return self.get_account()
|
|
|
|
|
|
|
|
|
|
|
|
def delete_account(self):
|
|
|
|
def delete_account(self):
|
|
|
|
if self.account_dict['provisioning_state'] == self.storage_models.ProvisioningState.succeeded.value and \
|
|
|
|
if self.account_dict['provisioning_state'] == self.storage_models.ProvisioningState.succeeded.value and \
|
|
|
|
self.account_has_blob_containers() and self.force:
|
|
|
|
not self.force_delete_nonempty and self.account_has_blob_containers():
|
|
|
|
self.fail("Account contains blob containers. Is it in use? Use the force option to attempt deletion.")
|
|
|
|
self.fail("Account contains blob containers. Is it in use? Use the force_delete_nonempty option to attempt deletion.")
|
|
|
|
|
|
|
|
|
|
|
|
self.log('Delete storage account {0}'.format(self.name))
|
|
|
|
self.log('Delete storage account {0}'.format(self.name))
|
|
|
|
self.results['changed'] = True
|
|
|
|
self.results['changed'] = True
|
|
|
@ -451,6 +578,15 @@ class AzureRMStorageAccount(AzureRMModuleBase):
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_blob_cors(self):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
cors_rules = self.storage_models.CorsRules(cors_rules=[self.storage_models.CorsRule(**x) for x in self.blob_cors])
|
|
|
|
|
|
|
|
self.storage_client.blob_services.set_service_properties(self.resource_group,
|
|
|
|
|
|
|
|
self.name,
|
|
|
|
|
|
|
|
self.storage_models.BlobServiceProperties(cors=cors_rules))
|
|
|
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
|
|
|
self.fail("Failed to set CORS rules: {0}".format(str(exc)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
AzureRMStorageAccount()
|
|
|
|
AzureRMStorageAccount()
|
|
|
|