keep backwards compatibility

This commit is contained in:
Matias De Carli 2015-10-03 13:48:10 -03:00 committed by Matt Clay
parent 607b7c14bd
commit f2bc0a6d85

View file

@ -249,22 +249,29 @@ AZURE_ROLE_SIZES = ['ExtraSmall',
'Standard_G4', 'Standard_G4',
'Standard_G5'] 'Standard_G5']
from distutils.version import LooseVersion
try: try:
import azure as windows_azure import azure as windows_azure
from azure.common import AzureException, AzureMissingResourceHttpError if hasattr(windows_azure, '__version__') and LooseVersion(windows_azure.__version__) <= "0.11.1":
from azure import WindowsAzureError as AzureException
from azure import WindowsAzureMissingResourceError as AzureMissingException
else:
from azure.common import AzureException as AzureException
from azure.common import AzureMissingResourceHttpError as AzureMissingException
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)
HAS_AZURE = True HAS_AZURE = True
except ImportError: except ImportError:
HAS_AZURE = False HAS_AZURE = False
from distutils.version import LooseVersion
from types import MethodType from types import MethodType
import json import json
def _wait_for_completion(azure, promise, wait_timeout, msg): def _wait_for_completion(azure, promise, wait_timeout, msg):
if not promise: return if not promise: return
wait_timeout = time.time() + wait_timeout wait_timeout = time.time() + wait_timeout
@ -353,7 +360,7 @@ def create_virtual_machine(module, azure):
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 AzureMissingResourceHttpError: except AzureMissingException:
# vm does not exist; create it # vm does not exist; create it
if os_type == 'linux': if os_type == 'linux':
@ -453,7 +460,7 @@ 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 AzureMissingResourceHttpError, e: except AzureMissingException, e:
pass # no such deployment or service pass # no such deployment or service
except AzureException, 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))
@ -545,6 +552,11 @@ 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 hasattr(windows_azure, '__version__') and 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