Fix ec2_ami block_device_mapping volume_size to be int in 2.5 (#40938)

* fix ec2_ami block_device_mapping size to be int

* fixed cr issues

renamed `type` to `attribute_type`
reused `new_item` instead of creating new variable `value`
pull/41095/head
Tine Jozelj 7 years ago committed by Ryan Brown
parent 92a95368fe
commit ab96a84154

@ -420,8 +420,8 @@ def create_image(module, connection):
device = rename_item_if_exists(device, 'volume_type', 'VolumeType', 'Ebs') device = rename_item_if_exists(device, 'volume_type', 'VolumeType', 'Ebs')
device = rename_item_if_exists(device, 'snapshot_id', 'SnapshotId', 'Ebs') device = rename_item_if_exists(device, 'snapshot_id', 'SnapshotId', 'Ebs')
device = rename_item_if_exists(device, 'delete_on_termination', 'DeleteOnTermination', 'Ebs') device = rename_item_if_exists(device, 'delete_on_termination', 'DeleteOnTermination', 'Ebs')
device = rename_item_if_exists(device, 'size', 'VolumeSize', 'Ebs') device = rename_item_if_exists(device, 'size', 'VolumeSize', 'Ebs', attribute_type=int)
device = rename_item_if_exists(device, 'volume_size', 'VolumeSize', 'Ebs') device = rename_item_if_exists(device, 'volume_size', 'VolumeSize', 'Ebs', attribute_type=int)
device = rename_item_if_exists(device, 'iops', 'Iops', 'Ebs') device = rename_item_if_exists(device, 'iops', 'Iops', 'Ebs')
device = rename_item_if_exists(device, 'encrypted', 'Encrypted', 'Ebs') device = rename_item_if_exists(device, 'encrypted', 'Encrypted', 'Ebs')
block_device_mapping.append(device) block_device_mapping.append(device)
@ -626,13 +626,15 @@ def get_image_by_id(module, connection, image_id):
module.fail_json_aws(e, msg="Error retrieving image by image_id") module.fail_json_aws(e, msg="Error retrieving image by image_id")
def rename_item_if_exists(dict_object, attribute, new_attribute, child_node=None): def rename_item_if_exists(dict_object, attribute, new_attribute, child_node=None, attribute_type=None):
new_item = dict_object.get(attribute) new_item = dict_object.get(attribute)
if new_item is not None: if new_item is not None:
if attribute_type is not None:
new_item = attribute_type(new_item)
if child_node is None: if child_node is None:
dict_object[new_attribute] = dict_object.get(attribute) dict_object[new_attribute] = new_item
else: else:
dict_object[child_node][new_attribute] = dict_object.get(attribute) dict_object[child_node][new_attribute] = new_item
dict_object.pop(attribute) dict_object.pop(attribute)
return dict_object return dict_object

Loading…
Cancel
Save