[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:
s-hertel 2017-02-10 15:22:38 -05:00 committed by Ryan Brown
parent 74e8aa22af
commit 2dc42fce80
2 changed files with 23 additions and 8 deletions

View file

@ -23,7 +23,9 @@ DOCUMENTATION = '''
module: ec2_vol module: ec2_vol
short_description: create and attach a volume, return volume id and device map short_description: create and attach a volume, return volume id and device map
description: 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" version_added: "1.1"
options: options:
instance: instance:
@ -50,7 +52,8 @@ options:
default: null default: null
volume_type: volume_type:
description: 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 required: false
default: standard default: standard
version_added: "1.9" version_added: "1.9"
@ -108,6 +111,13 @@ options:
default: present default: present
choices: ['absent', 'present', 'list'] choices: ['absent', 'present', 'list']
version_added: "1.6" 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)" author: "Lester Wade (@lwade)"
extends_documentation_fragment: extends_documentation_fragment:
- aws - aws
@ -341,6 +351,7 @@ def create_volume(module, ec2, zone):
volume_size = module.params.get('volume_size') volume_size = module.params.get('volume_size')
volume_type = module.params.get('volume_type') volume_type = module.params.get('volume_type')
snapshot = module.params.get('snapshot') 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 custom iops is defined we use volume_type "io1" rather than the default of "standard"
if iops: if iops:
volume_type = 'io1' volume_type = 'io1'
@ -363,7 +374,9 @@ def create_volume(module, ec2, zone):
volume.update() volume.update()
if name: 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: except boto.exception.BotoServerError as e:
module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message)) module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message))
@ -508,7 +521,8 @@ def main():
delete_on_termination = dict(type='bool', default=False), delete_on_termination = dict(type='bool', default=False),
zone = dict(aliases=['availability_zone', 'aws_zone', 'ec2_zone']), zone = dict(aliases=['availability_zone', 'aws_zone', 'ec2_zone']),
snapshot = dict(), 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) module = AnsibleModule(argument_spec=argument_spec)
@ -526,6 +540,7 @@ def main():
zone = module.params.get('zone') zone = module.params.get('zone')
snapshot = module.params.get('snapshot') snapshot = module.params.get('snapshot')
state = module.params.get('state') state = module.params.get('state')
tags = module.params.get('tags')
# Ensure we have the zone or can get the zone # Ensure we have the zone or can get the zone
if instance is None and zone is None and state == 'present': 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 # Add device, volume_id and volume_type parameters separately to maintain backward compatibility
volume_info = get_volume_info(volume, state) 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': elif state == 'absent':
delete_volume(module, ec2) delete_volume(module, ec2)

View file

@ -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_scaling_policy.py
lib/ansible/modules/cloud/amazon/ec2_snapshot_facts.py lib/ansible/modules/cloud/amazon/ec2_snapshot_facts.py
lib/ansible/modules/cloud/amazon/ec2_tag.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_vol_facts.py
lib/ansible/modules/cloud/amazon/ec2_vpc_dhcp_options_facts.py lib/ansible/modules/cloud/amazon/ec2_vpc_dhcp_options_facts.py
lib/ansible/modules/cloud/amazon/ec2_vpc_nacl.py lib/ansible/modules/cloud/amazon/ec2_vpc_nacl.py