Several azure fixes

Several azure fixes/improvements, including:
* Improve failure message when python-azure is not installed
* Improve required argument handling
* Fixes a traceback on instance termination when the variable
'deployment' was not set.
* Fixes a traceback (#8298) when creating instances using the newer SDK
reviewable/pr18780/r1
James Laska 10 years ago
parent a6da95ec7e
commit ff401c41c6

@ -179,8 +179,7 @@ try:
PublicKey, LinuxConfigurationSet, ConfigurationSetInputEndpoints, PublicKey, LinuxConfigurationSet, ConfigurationSetInputEndpoints,
ConfigurationSetInputEndpoint) ConfigurationSetInputEndpoint)
except ImportError: except ImportError:
print print "failed=True msg='azure required for this module'"
"failed=True msg='azure required for this module'"
sys.exit(1) sys.exit(1)
from distutils.version import LooseVersion from distutils.version import LooseVersion
@ -338,6 +337,7 @@ def terminate_virtual_machine(module, azure):
changed = False changed = False
deployment = None deployment = None
public_dns_name = None
disk_names = [] disk_names = []
try: try:
deployment = azure.get_deployment_by_name(service_name=name, deployment_name=name) deployment = azure.get_deployment_by_name(service_name=name, deployment_name=name)
@ -368,18 +368,24 @@ def terminate_virtual_machine(module, azure):
_wait_for_completion(azure, result, wait_timeout, "delete_hosted_service") _wait_for_completion(azure, result, wait_timeout, "delete_hosted_service")
except WindowsAzureError as e: except WindowsAzureError as e:
module.fail_json(msg="failed to delete the service %s, error was: %s" % (name, str(e))) module.fail_json(msg="failed to delete the service %s, error was: %s" % (name, str(e)))
public_dns_name = urlparse(deployment.url).hostname
return changed, urlparse(deployment.url).hostname, deployment return changed, public_dns_name, deployment
def get_azure_creds(module): def get_azure_creds(module):
# Check modul args for credentials, then check environment vars # Check modul args for credentials, then check environment vars
subscription_id = module.params.get('subscription_id') subscription_id = module.params.get('subscription_id')
management_cert_path = module.params.get('management_cert_path')
if not subscription_id: if not subscription_id:
subscription_id = os.environ['AZURE_SUBSCRIPTION_ID'] subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', None)
management_cert_path = os.environ['AZURE_CERT_PATH'] if not subscription_id:
module.fail_json(msg="No subscription_id provided. Please set 'AZURE_SUBSCRIPTION_ID' or use the 'subscription_id' parameter")
management_cert_path = module.params.get('management_cert_path')
if not management_cert_path:
management_cert_path = os.environ.get('AZURE_CERT_PATH', None)
if not management_cert_path:
module.fail_json(msg="No management_cert_path provided. Please set 'AZURE_CERT_PATH' or use the 'management_cert_path' parameter")
return subscription_id, management_cert_path return subscription_id, management_cert_path
@ -414,7 +420,7 @@ def main():
# wrapper for handling redirects which the sdk <= 0.8.0 is not following # wrapper for handling redirects which the sdk <= 0.8.0 is not following
azure = Wrapper(ServiceManagementService(subscription_id, management_cert_path), wait_timeout_redirects) azure = Wrapper(ServiceManagementService(subscription_id, management_cert_path), wait_timeout_redirects)
else: else:
azure = ServiceManagementService(subscription_id, management_cert_path), wait_timeout_redirects azure = ServiceManagementService(subscription_id, management_cert_path)
cloud_service_raw = None cloud_service_raw = None
if module.params.get('state') == 'absent': if module.params.get('state') == 'absent':

Loading…
Cancel
Save