updated dependencies to work with azure.py 1.0.1

pull/18777/head
Matias De Carli 9 years ago committed by Matt Clay
parent d46894cf91
commit d32809cadb

@ -252,7 +252,7 @@ AZURE_ROLE_SIZES = ['ExtraSmall',
try: try:
import azure as windows_azure import azure as windows_azure
from azure import WindowsAzureError, WindowsAzureMissingResourceError from azure.common import AzureException, AzureMissingResourceHttpError
from azure.servicemanagement import (ServiceManagementService, OSVirtualHardDisk, SSH, PublicKeys, from azure.servicemanagement import (ServiceManagementService, OSVirtualHardDisk, SSH, PublicKeys,
PublicKey, LinuxConfigurationSet, ConfigurationSetInputEndpoints, PublicKey, LinuxConfigurationSet, ConfigurationSetInputEndpoints,
ConfigurationSetInputEndpoint, Listener, WindowsConfigurationSet) ConfigurationSetInputEndpoint, Listener, WindowsConfigurationSet)
@ -274,7 +274,7 @@ def _wait_for_completion(azure, promise, wait_timeout, msg):
if operation_result.status == "Succeeded": if operation_result.status == "Succeeded":
return return
raise WindowsAzureError('Timed out waiting for async operation ' + msg + ' "' + str(promise.request_id) + '" to complete.') raise AzureException('Timed out waiting for async operation ' + msg + ' "' + str(promise.request_id) + '" to complete.')
def _delete_disks_when_detached(azure, wait_timeout, disk_names): def _delete_disks_when_detached(azure, wait_timeout, disk_names):
def _handle_timeout(signum, frame): def _handle_timeout(signum, frame):
@ -289,7 +289,7 @@ def _delete_disks_when_detached(azure, wait_timeout, disk_names):
if disk.attached_to is None: if disk.attached_to is None:
azure.delete_disk(disk.name, True) azure.delete_disk(disk.name, True)
disk_names.remove(disk_name) disk_names.remove(disk_name)
except WindowsAzureError, e: except AzureException, e:
module.fail_json(msg="failed to get or delete disk, error was: %s" % (disk_name, str(e))) module.fail_json(msg="failed to get or delete disk, error was: %s" % (disk_name, str(e)))
finally: finally:
signal.alarm(0) signal.alarm(0)
@ -347,13 +347,13 @@ def create_virtual_machine(module, azure):
result = azure.create_hosted_service(service_name=name, label=name, location=location) result = azure.create_hosted_service(service_name=name, label=name, location=location)
_wait_for_completion(azure, result, wait_timeout, "create_hosted_service") _wait_for_completion(azure, result, wait_timeout, "create_hosted_service")
changed = True changed = True
except WindowsAzureError, e: except AzureException, e:
module.fail_json(msg="failed to create the new service, error was: %s" % str(e)) module.fail_json(msg="failed to create the new service, error was: %s" % str(e))
try: try:
# check to see if a vm with this name exists; if so, do nothing # check to see if a vm with this name exists; if so, do nothing
azure.get_role(name, name, name) azure.get_role(name, name, name)
except WindowsAzureMissingResourceError: except AzureMissingResourceHttpError:
# vm does not exist; create it # vm does not exist; create it
if os_type == 'linux': if os_type == 'linux':
@ -419,13 +419,13 @@ def create_virtual_machine(module, azure):
virtual_network_name=virtual_network_name) virtual_network_name=virtual_network_name)
_wait_for_completion(azure, result, wait_timeout, "create_virtual_machine_deployment") _wait_for_completion(azure, result, wait_timeout, "create_virtual_machine_deployment")
changed = True changed = True
except WindowsAzureError, e: except AzureException, e:
module.fail_json(msg="failed to create the new virtual machine, error was: %s" % str(e)) module.fail_json(msg="failed to create the new virtual machine, error was: %s" % str(e))
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)
return (changed, urlparse(deployment.url).hostname, deployment) return (changed, urlparse(deployment.url).hostname, deployment)
except WindowsAzureError, e: except AzureException, e:
module.fail_json(msg="failed to lookup the deployment information for %s, error was: %s" % (name, str(e))) module.fail_json(msg="failed to lookup the deployment information for %s, error was: %s" % (name, str(e)))
@ -453,9 +453,9 @@ def terminate_virtual_machine(module, azure):
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)
except WindowsAzureMissingResourceError, e: except AzureMissingResourceHttpError, e:
pass # no such deployment or service pass # no such deployment or service
except WindowsAzureError, e: except AzureException, e:
module.fail_json(msg="failed to find the deployment, error was: %s" % str(e)) module.fail_json(msg="failed to find the deployment, error was: %s" % str(e))
# Delete deployment # Delete deployment
@ -468,13 +468,13 @@ def terminate_virtual_machine(module, azure):
role_props = azure.get_role(name, deployment.name, role.role_name) role_props = azure.get_role(name, deployment.name, role.role_name)
if role_props.os_virtual_hard_disk.disk_name not in disk_names: if role_props.os_virtual_hard_disk.disk_name not in disk_names:
disk_names.append(role_props.os_virtual_hard_disk.disk_name) disk_names.append(role_props.os_virtual_hard_disk.disk_name)
except WindowsAzureError, e: except AzureException, e:
module.fail_json(msg="failed to get the role %s, error was: %s" % (role.role_name, str(e))) module.fail_json(msg="failed to get the role %s, error was: %s" % (role.role_name, str(e)))
try: try:
result = azure.delete_deployment(name, deployment.name) result = azure.delete_deployment(name, deployment.name)
_wait_for_completion(azure, result, wait_timeout, "delete_deployment") _wait_for_completion(azure, result, wait_timeout, "delete_deployment")
except WindowsAzureError, e: except AzureException, e:
module.fail_json(msg="failed to delete the deployment %s, error was: %s" % (deployment.name, str(e))) module.fail_json(msg="failed to delete the deployment %s, error was: %s" % (deployment.name, str(e)))
# It's unclear when disks associated with terminated deployment get detatched. # It's unclear when disks associated with terminated deployment get detatched.
@ -482,14 +482,14 @@ def terminate_virtual_machine(module, azure):
# become detatched by polling the list of remaining disks and examining the state. # become detatched by polling the list of remaining disks and examining the state.
try: try:
_delete_disks_when_detached(azure, wait_timeout, disk_names) _delete_disks_when_detached(azure, wait_timeout, disk_names)
except (WindowsAzureError, TimeoutError), e: except (AzureException, TimeoutError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
try: try:
# Now that the vm is deleted, remove the cloud service # Now that the vm is deleted, remove the cloud service
result = azure.delete_hosted_service(service_name=name) result = azure.delete_hosted_service(service_name=name)
_wait_for_completion(azure, result, wait_timeout, "delete_hosted_service") _wait_for_completion(azure, result, wait_timeout, "delete_hosted_service")
except WindowsAzureError, e: except AzureException, 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 public_dns_name = urlparse(deployment.url).hostname
@ -545,10 +545,6 @@ def main():
subscription_id, management_cert_path = get_azure_creds(module) subscription_id, management_cert_path = get_azure_creds(module)
wait_timeout_redirects = int(module.params.get('wait_timeout_redirects')) wait_timeout_redirects = int(module.params.get('wait_timeout_redirects'))
if LooseVersion(windows_azure.__version__) <= "0.8.0":
# wrapper for handling redirects which the sdk <= 0.8.0 is not following
azure = Wrapper(ServiceManagementService(subscription_id, management_cert_path), wait_timeout_redirects)
else:
azure = ServiceManagementService(subscription_id, management_cert_path) azure = ServiceManagementService(subscription_id, management_cert_path)
cloud_service_raw = None cloud_service_raw = None
@ -597,7 +593,7 @@ class Wrapper(object):
while wait_timeout > time.time(): while wait_timeout > time.time():
try: try:
return f() return f()
except WindowsAzureError, e: except AzureException, e:
if not str(e).lower().find("temporary redirect") == -1: if not str(e).lower().find("temporary redirect") == -1:
time.sleep(5) time.sleep(5)
pass pass

Loading…
Cancel
Save