Protect against older libcloud versions

This commit is contained in:
Pedro Algarvio 2014-09-16 02:25:55 +01:00
parent d12b0f10c5
commit 97762f845d
2 changed files with 24 additions and 20 deletions

View File

@ -1873,22 +1873,27 @@ def create(vm_=None, call=None):
'ex_metadata': __get_metadata(vm_),
'external_ip': config.get_cloud_config_value(
'external_ip', vm_, __opts__, default='ephemeral'
),
'ex_disk_type': config.get_cloud_config_value(
'ex_disk_type', vm_, __opts__, default='pd-standard'),
'ex_disk_auto_delete': config.get_cloud_config_value(
'ex_disk_auto_delete', vm_, __opts__, default=True)
)
}
if LIBCLOUD_VERSION_INFO > (0, 15, 1):
# This only exists in current trunk of libcloud and should be in next
# release
kwargs.update({
'ex_disk_type': config.get_cloud_config_value(
'ex_disk_type', vm_, __opts__, default='pd-standard'),
'ex_disk_auto_delete': config.get_cloud_config_value(
'ex_disk_auto_delete', vm_, __opts__, default=True)
})
if kwargs.get('ex_disk_type') not in ('pd-standard', 'pd-ssd'):
raise SaltCloudSystemExit(
'The value of \'ex_disk_type\' needs to be one of: '
'\'pd-standard\', \'pd-ssd\''
)
if 'external_ip' in kwargs and kwargs['external_ip'] == "None":
kwargs['external_ip'] = None
if kwargs.get('ex_disk_type') not in ('pd-standard', 'pd-ssd'):
raise SaltCloudSystemExit(
'The value of \'ex_disk_type\' needs to be one of: '
'\'pd-standard\', \'pd-ssd\''
)
log.info('Creating GCE instance {0} in {1}'.format(vm_['name'],
kwargs['location'].name)
)

View File

@ -12,6 +12,7 @@ import logging
# pylint: disable=W0611
# Import libcloud
try:
import libcloud
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
from libcloud.compute.deployment import (
@ -20,8 +21,13 @@ try:
SSHKeyDeployment
)
HAS_LIBCLOUD = True
LIBCLOUD_VERSION_INFO = tuple([
int(part) for part in libcloud.__version__.replace('-', '.').split()[:3]
])
except ImportError:
HAS_LIBCLOUD = False
LIBCLOUD_VERSION_INFO = (1000,)
# pylint: enable=W0611
@ -68,7 +74,7 @@ def check_libcloud_version(reqver=LIBCLOUD_MINIMAL_VERSION, why=None):
'\'reqver\' needs to passed as a tuple or list, ie, (0, 14, 0)'
)
try:
import libcloud
import libcloud # pylint: disable=redefined-outer-name
except ImportError:
raise ImportError(
'salt-cloud requires >= libcloud {0} which is not installed'.format(
@ -76,14 +82,7 @@ def check_libcloud_version(reqver=LIBCLOUD_MINIMAL_VERSION, why=None):
)
)
ver = libcloud.__version__
ver = ver.replace('-', '.')
comps = ver.split('.')
version = []
for number in comps[:3]:
version.append(int(number))
if tuple(version) >= reqver:
if LIBCLOUD_VERSION_INFO >= reqver:
return libcloud.__version__
errormsg = 'Your version of libcloud is {0}. '.format(libcloud.__version__)