mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
Port azure_rm_common.py to py3 syntax (#15880)
Since the rest of the file already use a non 2.4 syntax (such as format), I didn't bother using the 2.4 syntax for exceptions.
This commit is contained in:
parent
1e60fb6c19
commit
eb52dc9af0
1 changed files with 9 additions and 9 deletions
|
@ -88,7 +88,7 @@ try:
|
||||||
from azure.mgmt.compute.compute_management_client import ComputeManagementClient,\
|
from azure.mgmt.compute.compute_management_client import ComputeManagementClient,\
|
||||||
ComputeManagementClientConfiguration
|
ComputeManagementClientConfiguration
|
||||||
from azure.storage.cloudstorageaccount import CloudStorageAccount
|
from azure.storage.cloudstorageaccount import CloudStorageAccount
|
||||||
except ImportError, exc:
|
except ImportError as exc:
|
||||||
HAS_AZURE_EXC = exc
|
HAS_AZURE_EXC = exc
|
||||||
HAS_AZURE = False
|
HAS_AZURE = False
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ class AzureRMModuleBase(object):
|
||||||
return self.rm_client.resource_groups.get(resource_group)
|
return self.rm_client.resource_groups.get(resource_group)
|
||||||
except CloudError:
|
except CloudError:
|
||||||
self.fail("Parameter error: resource group {0} not found".format(resource_group))
|
self.fail("Parameter error: resource group {0} not found".format(resource_group))
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.fail("Error retrieving resource group {0} - {1}".format(resource_group, str(exc)))
|
self.fail("Error retrieving resource group {0} - {1}".format(resource_group, str(exc)))
|
||||||
|
|
||||||
def _get_profile(self, profile="default"):
|
def _get_profile(self, profile="default"):
|
||||||
|
@ -331,7 +331,7 @@ class AzureRMModuleBase(object):
|
||||||
try:
|
try:
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read(path)
|
config.read(path)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.fail("Failed to access {0}. Check that the file exists and you have read "
|
self.fail("Failed to access {0}. Check that the file exists and you have read "
|
||||||
"access. {1}".format(path, str(exc)))
|
"access. {1}".format(path, str(exc)))
|
||||||
credentials = dict()
|
credentials = dict()
|
||||||
|
@ -418,7 +418,7 @@ class AzureRMModuleBase(object):
|
||||||
self.log("Waiting for {0} sec".format(delay))
|
self.log("Waiting for {0} sec".format(delay))
|
||||||
poller.wait(timeout=delay)
|
poller.wait(timeout=delay)
|
||||||
return poller.result()
|
return poller.result()
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.log(str(exc))
|
self.log(str(exc))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -465,13 +465,13 @@ class AzureRMModuleBase(object):
|
||||||
account_keys = self.storage_client.storage_accounts.list_keys(resource_group_name, storage_account_name)
|
account_keys = self.storage_client.storage_accounts.list_keys(resource_group_name, storage_account_name)
|
||||||
keys['key1'] = account_keys.key1
|
keys['key1'] = account_keys.key1
|
||||||
keys['key2'] = account_keys.key2
|
keys['key2'] = account_keys.key2
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.fail("Error getting keys for account {0} - {1}".format(storage_account_name, str(exc)))
|
self.fail("Error getting keys for account {0} - {1}".format(storage_account_name, str(exc)))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.log('Create blob service')
|
self.log('Create blob service')
|
||||||
return CloudStorageAccount(storage_account_name, keys['key1']).create_block_blob_service()
|
return CloudStorageAccount(storage_account_name, keys['key1']).create_block_blob_service()
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.fail("Error creating blob service client for storage account {0} - {1}".format(storage_account_name,
|
self.fail("Error creating blob service client for storage account {0} - {1}".format(storage_account_name,
|
||||||
str(exc)))
|
str(exc)))
|
||||||
|
|
||||||
|
@ -508,7 +508,7 @@ class AzureRMModuleBase(object):
|
||||||
self.log('Creating default public IP {0}'.format(public_ip_name))
|
self.log('Creating default public IP {0}'.format(public_ip_name))
|
||||||
try:
|
try:
|
||||||
poller = self.network_client.public_ip_addresses.create_or_update(resource_group, public_ip_name, params)
|
poller = self.network_client.public_ip_addresses.create_or_update(resource_group, public_ip_name, params)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.fail("Error creating {0} - {1}".format(public_ip_name, str(exc)))
|
self.fail("Error creating {0} - {1}".format(public_ip_name, str(exc)))
|
||||||
|
|
||||||
return self.get_poller_result(poller)
|
return self.get_poller_result(poller)
|
||||||
|
@ -578,7 +578,7 @@ class AzureRMModuleBase(object):
|
||||||
poller = self.network_client.network_security_groups.create_or_update(resource_group,
|
poller = self.network_client.network_security_groups.create_or_update(resource_group,
|
||||||
security_group_name,
|
security_group_name,
|
||||||
parameters)
|
parameters)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.fail("Error creating default security rule {0} - {1}".format(security_group_name, str(exc)))
|
self.fail("Error creating default security rule {0} - {1}".format(security_group_name, str(exc)))
|
||||||
|
|
||||||
return self.get_poller_result(poller)
|
return self.get_poller_result(poller)
|
||||||
|
@ -589,7 +589,7 @@ class AzureRMModuleBase(object):
|
||||||
# time we attempt to use the requested client.
|
# time we attempt to use the requested client.
|
||||||
resource_client = self.rm_client
|
resource_client = self.rm_client
|
||||||
resource_client.providers.register(key)
|
resource_client.providers.register(key)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.fail("One-time registration of {0} failed - {1}".format(key, str(exc)))
|
self.fail("One-time registration of {0} failed - {1}".format(key, str(exc)))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue