mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix issue which prevents creating ec2 instance with extra volumes when using a older version of boto not supporting volume encryption. Fix issue #1173
This commit is contained in:
parent
f8fa772a55
commit
e2c50baf3f
1 changed files with 32 additions and 13 deletions
|
@ -603,6 +603,8 @@ from ast import literal_eval
|
||||||
from ansible.module_utils.six import iteritems
|
from ansible.module_utils.six import iteritems
|
||||||
from ansible.module_utils.six import get_function_code
|
from ansible.module_utils.six import get_function_code
|
||||||
|
|
||||||
|
from distutils.version import LooseVersion
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import boto.ec2
|
import boto.ec2
|
||||||
from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
|
from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
|
||||||
|
@ -768,6 +770,15 @@ def boto_supports_profile_name_arg(ec2):
|
||||||
run_instances_method = getattr(ec2, 'run_instances')
|
run_instances_method = getattr(ec2, 'run_instances')
|
||||||
return 'instance_profile_name' in get_function_code(run_instances_method).co_varnames
|
return 'instance_profile_name' in get_function_code(run_instances_method).co_varnames
|
||||||
|
|
||||||
|
def boto_supports_volume_encryption():
|
||||||
|
"""
|
||||||
|
Check if Boto library supports encryption of EBS volumes (added in 2.29.0)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if boto library has the named param as an argument on the request_spot_instances method, else False
|
||||||
|
"""
|
||||||
|
return hasattr(boto, 'Version') and LooseVersion(boto.Version) >= LooseVersion('2.29.0')
|
||||||
|
|
||||||
def create_block_device(module, ec2, volume):
|
def create_block_device(module, ec2, volume):
|
||||||
# Not aware of a way to determine this programatically
|
# Not aware of a way to determine this programatically
|
||||||
# http://aws.amazon.com/about-aws/whats-new/2013/10/09/ebs-provisioned-iops-maximum-iops-gb-ratio-increased-to-30-1/
|
# http://aws.amazon.com/about-aws/whats-new/2013/10/09/ebs-provisioned-iops-maximum-iops-gb-ratio-increased-to-30-1/
|
||||||
|
@ -798,13 +809,21 @@ def create_block_device(module, ec2, volume):
|
||||||
if 'ephemeral' in volume:
|
if 'ephemeral' in volume:
|
||||||
if 'snapshot' in volume:
|
if 'snapshot' in volume:
|
||||||
module.fail_json(msg = 'Cannot set both ephemeral and snapshot')
|
module.fail_json(msg = 'Cannot set both ephemeral and snapshot')
|
||||||
return BlockDeviceType(snapshot_id=volume.get('snapshot'),
|
if boto_supports_volume_encryption():
|
||||||
ephemeral_name=volume.get('ephemeral'),
|
return BlockDeviceType(snapshot_id=volume.get('snapshot'),
|
||||||
size=volume.get('volume_size'),
|
ephemeral_name=volume.get('ephemeral'),
|
||||||
volume_type=volume_type,
|
size=volume.get('volume_size'),
|
||||||
delete_on_termination=volume.get('delete_on_termination', False),
|
volume_type=volume_type,
|
||||||
iops=volume.get('iops'),
|
delete_on_termination=volume.get('delete_on_termination', False),
|
||||||
encrypted=volume.get('encrypted', None))
|
iops=volume.get('iops'),
|
||||||
|
encrypted=volume.get('encrypted', None))
|
||||||
|
else:
|
||||||
|
return BlockDeviceType(snapshot_id=volume.get('snapshot'),
|
||||||
|
ephemeral_name=volume.get('ephemeral'),
|
||||||
|
size=volume.get('volume_size'),
|
||||||
|
volume_type=volume_type,
|
||||||
|
delete_on_termination=volume.get('delete_on_termination', False),
|
||||||
|
iops=volume.get('iops'))
|
||||||
|
|
||||||
def boto_supports_param_in_spot_request(ec2, param):
|
def boto_supports_param_in_spot_request(ec2, param):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue