Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2_vol: Limit the scope of new botocore requirements #346

Merged
merged 3 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/346-ec2_vol-boto3-requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_vol - relax the boto3/botocore requirements and only require botocore 1.19.27 for modifying the ``throughput`` parameter (https://github.com/ansible-collections/amazon.aws/pull/346).
20 changes: 13 additions & 7 deletions plugins/modules/ec2_vol.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@
- Volume throughput in MB/s.
- This parameter is only valid for gp3 volumes.
- Valid range is from 125 to 1000.
- Requires at least botocore version 1.19.27.
type: int
version_added: 1.4.0
author: "Lester Wade (@lwade)"
extends_documentation_fragment:
- amazon.aws.aws
- amazon.aws.ec2

requirements: [ boto3>=1.16.33 ]
'''

EXAMPLES = '''
Expand Down Expand Up @@ -401,7 +400,8 @@ def update_volume(module, ec2_conn, volume):
volume['size'] = response.get('VolumeModification').get('TargetSize')
volume['volume_type'] = response.get('VolumeModification').get('TargetVolumeType')
volume['iops'] = response.get('VolumeModification').get('TargetIops')
volume['throughput'] = response.get('VolumeModification').get('TargetThroughput')
if module.botocore_at_least("1.19.27"):
volume['throughput'] = response.get('VolumeModification').get('TargetThroughput')

return volume, changed

Expand Down Expand Up @@ -570,7 +570,7 @@ def detach_volume(module, ec2_conn, volume_dict):
return volume_dict, changed


def get_volume_info(volume, tags=None):
def get_volume_info(module, volume, tags=None):
if not tags:
tags = boto3_tag_list_to_ansible_dict(volume.get('tags'))
attachment_data = get_attachment_data(volume)
Expand All @@ -584,7 +584,6 @@ def get_volume_info(volume, tags=None):
'status': volume.get('state'),
'type': volume.get('volume_type'),
'zone': volume.get('availability_zone'),
'throughput': volume.get('throughput'),
'attachment_set': {
'attach_time': attachment_data.get('attach_time', None),
'device': attachment_data.get('device', None),
Expand All @@ -595,6 +594,9 @@ def get_volume_info(volume, tags=None):
'tags': tags
}

if module.botocore_at_least("1.19.27"):
volume_info['throughput'] = volume.get('throughput')

return volume_info


Expand Down Expand Up @@ -657,6 +659,10 @@ def main():
module.deprecate(
'Using the "list" state has been deprecated. Please use the ec2_vol_info module instead', date='2022-06-01', collection_name='amazon.aws')

if module.params.get('throughput'):
if not module.botocore_at_least("1.19.27"):
module.fail_json(msg="botocore >= 1.19.27 is required to set the throughput for a volume")

# Ensure we have the zone or can get the zone
if instance is None and zone is None and state == 'present':
module.fail_json(msg="You must specify either instance or zone")
Expand All @@ -678,7 +684,7 @@ def main():
vols = get_volumes(module, ec2_conn)

for v in vols:
returned_volumes.append(get_volume_info(v))
returned_volumes.append(get_volume_info(module, v))

module.exit_json(changed=False, volumes=returned_volumes)

Expand Down Expand Up @@ -745,7 +751,7 @@ def main():
volume, changed = attach_volume(module, ec2_conn, volume_dict=volume, instance_dict=inst, device_name=device_name)

# Add device, volume_id and volume_type parameters separately to maintain backward compatibility
volume_info = get_volume_info(volume, tags=final_tags)
volume_info = get_volume_info(module, volume, tags=final_tags)

if tags_changed:
changed = True
Expand Down