mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[cloud] add tags parameter to ec2_vol
& PEP8 fixes (#21254)
* Make ec2_vol pep8 and add tags parameter * Remove ec2_vol.py from pep8 legacy-files
This commit is contained in:
parent
74e8aa22af
commit
2dc42fce80
2 changed files with 23 additions and 8 deletions
|
@ -23,7 +23,9 @@ DOCUMENTATION = '''
|
|||
module: ec2_vol
|
||||
short_description: create and attach a volume, return volume id and device map
|
||||
description:
|
||||
- creates an EBS volume and optionally attaches it to an instance. If both an instance ID and a device name is given and the instance has a device at the device name, then no volume is created and no attachment is made. This module has a dependency on python-boto.
|
||||
- creates an EBS volume and optionally attaches it to an instance.
|
||||
If both an instance ID and a device name is given and the instance has a device at the device name, then no volume is created and no attachment is made.
|
||||
This module has a dependency on python-boto.
|
||||
version_added: "1.1"
|
||||
options:
|
||||
instance:
|
||||
|
@ -50,7 +52,8 @@ options:
|
|||
default: null
|
||||
volume_type:
|
||||
description:
|
||||
- Type of EBS volume; standard (magnetic), gp2 (SSD), io1 (Provisioned IOPS), st1 (Throughput Optimized HDD), sc1 (Cold HDD). "Standard" is the old EBS default and continues to remain the Ansible default for backwards compatibility.
|
||||
- Type of EBS volume; standard (magnetic), gp2 (SSD), io1 (Provisioned IOPS), st1 (Throughput Optimized HDD), sc1 (Cold HDD).
|
||||
"Standard" is the old EBS default and continues to remain the Ansible default for backwards compatibility.
|
||||
required: false
|
||||
default: standard
|
||||
version_added: "1.9"
|
||||
|
@ -108,6 +111,13 @@ options:
|
|||
default: present
|
||||
choices: ['absent', 'present', 'list']
|
||||
version_added: "1.6"
|
||||
tags:
|
||||
description:
|
||||
- tag:value pairs to add to the volume after creation
|
||||
type: dict
|
||||
required: false
|
||||
default: {}
|
||||
version_added: "2.3"
|
||||
author: "Lester Wade (@lwade)"
|
||||
extends_documentation_fragment:
|
||||
- aws
|
||||
|
@ -341,6 +351,7 @@ def create_volume(module, ec2, zone):
|
|||
volume_size = module.params.get('volume_size')
|
||||
volume_type = module.params.get('volume_type')
|
||||
snapshot = module.params.get('snapshot')
|
||||
tags = module.params.get('tags')
|
||||
# If custom iops is defined we use volume_type "io1" rather than the default of "standard"
|
||||
if iops:
|
||||
volume_type = 'io1'
|
||||
|
@ -363,7 +374,9 @@ def create_volume(module, ec2, zone):
|
|||
volume.update()
|
||||
|
||||
if name:
|
||||
ec2.create_tags([volume.id], {"Name": name})
|
||||
tags["Name"] = name
|
||||
if tags:
|
||||
ec2.create_tags([volume.id], tags)
|
||||
except boto.exception.BotoServerError as e:
|
||||
module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message))
|
||||
|
||||
|
@ -484,9 +497,9 @@ def get_volume_info(volume, state):
|
|||
'device': attachment.device,
|
||||
'instance_id': attachment.instance_id,
|
||||
'status': attachment.status
|
||||
},
|
||||
},
|
||||
'tags': volume.tags
|
||||
}
|
||||
}
|
||||
if hasattr(attachment, 'deleteOnTermination'):
|
||||
volume_info['attachment_set']['deleteOnTermination'] = attachment.deleteOnTermination
|
||||
|
||||
|
@ -508,7 +521,8 @@ def main():
|
|||
delete_on_termination = dict(type='bool', default=False),
|
||||
zone = dict(aliases=['availability_zone', 'aws_zone', 'ec2_zone']),
|
||||
snapshot = dict(),
|
||||
state = dict(choices=['absent', 'present', 'list'], default='present')
|
||||
state = dict(choices=['absent', 'present', 'list'], default='present'),
|
||||
tags = dict(type='dict', default={})
|
||||
)
|
||||
)
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
|
@ -526,6 +540,7 @@ def main():
|
|||
zone = module.params.get('zone')
|
||||
snapshot = module.params.get('snapshot')
|
||||
state = module.params.get('state')
|
||||
tags = module.params.get('tags')
|
||||
|
||||
# Ensure we have the zone or can get the zone
|
||||
if instance is None and zone is None and state == 'present':
|
||||
|
@ -606,7 +621,8 @@ def main():
|
|||
|
||||
# Add device, volume_id and volume_type parameters separately to maintain backward compatibility
|
||||
volume_info = get_volume_info(volume, state)
|
||||
module.exit_json(changed=changed, volume=volume_info, device=volume_info['attachment_set']['device'], volume_id=volume_info['id'], volume_type=volume_info['type'])
|
||||
module.exit_json(changed=changed, volume=volume_info, device=volume_info['attachment_set']['device'],
|
||||
volume_id=volume_info['id'], volume_type=volume_info['type'])
|
||||
elif state == 'absent':
|
||||
delete_volume(module, ec2)
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ lib/ansible/modules/cloud/amazon/ec2_remote_facts.py
|
|||
lib/ansible/modules/cloud/amazon/ec2_scaling_policy.py
|
||||
lib/ansible/modules/cloud/amazon/ec2_snapshot_facts.py
|
||||
lib/ansible/modules/cloud/amazon/ec2_tag.py
|
||||
lib/ansible/modules/cloud/amazon/ec2_vol.py
|
||||
lib/ansible/modules/cloud/amazon/ec2_vol_facts.py
|
||||
lib/ansible/modules/cloud/amazon/ec2_vpc_dhcp_options_facts.py
|
||||
lib/ansible/modules/cloud/amazon/ec2_vpc_nacl.py
|
||||
|
|
Loading…
Reference in a new issue