mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Protect against older libcloud versions
This commit is contained in:
parent
d12b0f10c5
commit
97762f845d
@ -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'
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
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 '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\''
|
||||
)
|
||||
|
||||
if 'external_ip' in kwargs and kwargs['external_ip'] == "None":
|
||||
kwargs['external_ip'] = None
|
||||
|
||||
log.info('Creating GCE instance {0} in {1}'.format(vm_['name'],
|
||||
kwargs['location'].name)
|
||||
)
|
||||
|
@ -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__)
|
||||
|
Loading…
Reference in New Issue
Block a user