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 get_function_code
|
||||
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
try:
|
||||
import boto.ec2
|
||||
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')
|
||||
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):
|
||||
# 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/
|
||||
|
@ -798,6 +809,7 @@ def create_block_device(module, ec2, volume):
|
|||
if 'ephemeral' in volume:
|
||||
if 'snapshot' in volume:
|
||||
module.fail_json(msg = 'Cannot set both ephemeral and snapshot')
|
||||
if boto_supports_volume_encryption():
|
||||
return BlockDeviceType(snapshot_id=volume.get('snapshot'),
|
||||
ephemeral_name=volume.get('ephemeral'),
|
||||
size=volume.get('volume_size'),
|
||||
|
@ -805,6 +817,13 @@ def create_block_device(module, ec2, volume):
|
|||
delete_on_termination=volume.get('delete_on_termination', False),
|
||||
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):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue