From e6aeed2a8e5f2fa4e77254c150ef5a89d1ad078a Mon Sep 17 00:00:00 2001 From: Zhijun Zhao Date: Mon, 25 Dec 2017 17:08:33 +0800 Subject: [PATCH] pin api version of azure storage models --- lib/ansible/module_utils/azure_rm_common.py | 4 +-- .../cloud/azure/azure_rm_storageaccount.py | 30 +++++++++---------- .../cloud/azure/azure_rm_virtualmachine.py | 8 ++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/ansible/module_utils/azure_rm_common.py b/lib/ansible/module_utils/azure_rm_common.py index d3a95a33345..372dc6cc0c3 100644 --- a/lib/ansible/module_utils/azure_rm_common.py +++ b/lib/ansible/module_utils/azure_rm_common.py @@ -754,9 +754,9 @@ class AzureRMModuleBase(object): return self._storage_client @property - def storage_accounts_models(self): + def storage_models(self): self.log('Getting storage models...') - return self.storage_client.storage_accounts.models + return StorageManagementClient.models("2017-10-01") @property def network_client(self): diff --git a/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py b/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py index ff3948adefe..bff4633b391 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py @@ -153,9 +153,6 @@ try: from msrestazure.azure_exceptions import CloudError from azure.storage.cloudstorageaccount import CloudStorageAccount from azure.common import AzureMissingResourceHttpError - from azure.mgmt.storage.models import ProvisioningState, SkuName, SkuTier, Kind - from azure.mgmt.storage.models import StorageAccountUpdateParameters, CustomDomain, \ - StorageAccountCreateParameters, Sku except ImportError: # This is handled in azure_rm_common pass @@ -180,7 +177,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): access_tier=dict(type='str', choices=['Hot', 'Cool']) ) - for key in SkuName: + for key in self.storage_models.SkuName: self.module_arg_spec['account_type']['choices'].append(getattr(key, 'value')) self.results = dict( @@ -322,6 +319,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): if self.account_type: if self.account_type != self.account_dict['sku_name']: # change the account type + SkuName = self.storage_models.SkuName if self.account_dict['sku_name'] in [SkuName.premium_lrs, SkuName.standard_zrs]: self.fail("Storage accounts of type {0} and {1} cannot be changed.".format( SkuName.premium_lrs, SkuName.standard_zrs)) @@ -337,9 +335,9 @@ class AzureRMStorageAccount(AzureRMModuleBase): try: self.log("sku_name: %s" % self.account_dict['sku_name']) self.log("sku_tier: %s" % self.account_dict['sku_tier']) - sku = Sku(SkuName(self.account_dict['sku_name'])) - sku.tier = SkuTier(self.account_dict['sku_tier']) - parameters = StorageAccountUpdateParameters(sku=sku) + sku = self.storage_models.Sku(SkuName(self.account_dict['sku_name'])) + sku.tier = self.storage_models.SkuTier(self.account_dict['sku_tier']) + parameters = self.storage_models.StorageAccountUpdateParameters(sku=sku) self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters) @@ -352,9 +350,9 @@ class AzureRMStorageAccount(AzureRMModuleBase): self.account_dict['custom_domain'] = self.custom_domain if self.results['changed'] and not self.check_mode: - new_domain = CustomDomain(name=self.custom_domain['name'], + new_domain = self.storage_models.CustomDomain(name=self.custom_domain['name'], use_sub_domain=self.custom_domain['use_sub_domain']) - parameters = StorageAccountUpdateParameters(custom_domain=new_domain) + parameters = self.storage_models.StorageAccountUpdateParameters(custom_domain=new_domain) try: self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters) except Exception as exc: @@ -366,7 +364,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): self.account_dict['access_tier'] = self.access_tier if self.results['changed'] and not self.check_mode: - parameters = StorageAccountUpdateParameters(access_tier=self.access_tier) + parameters = self.storage_models.StorageAccountUpdateParameters(access_tier=self.access_tier) try: self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters) except Exception as exc: @@ -376,7 +374,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): if update_tags: self.results['changed'] = True if not self.check_mode: - parameters = StorageAccountUpdateParameters(tags=self.account_dict['tags']) + parameters = self.storage_models.StorageAccountUpdateParameters(tags=self.account_dict['tags']) try: self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters) except Exception as exc: @@ -408,9 +406,11 @@ class AzureRMStorageAccount(AzureRMModuleBase): if self.tags: account_dict['tags'] = self.tags return account_dict - sku = Sku(SkuName(self.account_type)) - sku.tier = SkuTier.standard if 'Standard' in self.account_type else SkuTier.premium - parameters = StorageAccountCreateParameters(sku, self.kind, self.location, tags=self.tags, access_tier=self.access_tier) + sku = self.storage_models.Sku(self.storage_models.SkuName(self.account_type)) + sku.tier = self.storage_models.SkuTier.standard if 'Standard' in self.account_type else \ + self.storage_models.SkuTier.premium + parameters = self.storage_models.StorageAccountCreateParameters(sku, self.kind, self.location, + tags=self.tags, access_tier=self.access_tier) self.log(str(parameters)) try: poller = self.storage_client.storage_accounts.create(self.resource_group, self.name, parameters) @@ -422,7 +422,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): return self.get_account() def delete_account(self): - if self.account_dict['provisioning_state'] == 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: self.fail("Account contains blob containers. Is it in use? Use the force option to attempt deletion.") diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py index df66d0c3685..79a3853e46e 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py @@ -1528,10 +1528,10 @@ class AzureRMVirtualMachine(AzureRMModuleBase): self.log("Storage account {0} found.".format(storage_account_name)) self.check_provisioning_state(account) return account - sku = self.storage_accounts_models.Sku(self.storage_accounts_models.SkuName.standard_lrs) - sku.tier = self.storage_accounts_models.SkuTier.standard - kind = self.storage_accounts_models.Kind.storage - parameters = self.storage_accounts_models.StorageAccountCreateParameters(sku, kind, self.location) + sku = self.storage_models.Sku(self.storage_models.SkuName.standard_lrs) + sku.tier = self.storage_models.SkuTier.standard + kind = self.storage_models.Kind.storage + parameters = self.storage_models.StorageAccountCreateParameters(sku, kind, self.location) self.log("Creating storage account {0} in location {1}".format(storage_account_name, self.location)) self.results['actions'].append("Created storage account {0}".format(storage_account_name)) try: