From 1410df43deb53ccfe2f7639b275bf4618b3e13b7 Mon Sep 17 00:00:00 2001 From: Ben Podoll Date: Fri, 2 Aug 2013 11:31:31 -0500 Subject: [PATCH] adding param to allow for specifying custom iops setting when creating an EBS volume --- library/cloud/ec2_vol | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/library/cloud/ec2_vol b/library/cloud/ec2_vol index c9116122859..8eefaf2946c 100644 --- a/library/cloud/ec2_vol +++ b/library/cloud/ec2_vol @@ -34,6 +34,12 @@ options: required: true default: null aliases: [] + iops: + description: + - the provisioned IOPs you want to associate with this volume (integer). + required: false + default: 100 + aliases: [] device_name: description: - device id to override device mapping. Assumes /dev/sdf for Linux/UNIX and /dev/xvdf for Windows. @@ -63,7 +69,15 @@ EXAMPLES = ''' instance: XXXXXX volume_size: 5 device_name: sdd - + +# Example using custom iops params +- local_action: + module: ec2_vol + instance: XXXXXX + volume_size: 5 + iops: 200 + device_name: sdd + # Playbook example combined with instance launch - local_action: module: ec2 @@ -99,6 +113,7 @@ def main(): argument_spec = dict( instance = dict(), volume_size = dict(required=True), + iops = dict(), device_name = dict(), region = dict(), zone = dict(), @@ -110,6 +125,7 @@ def main(): instance = module.params.get('instance') volume_size = module.params.get('volume_size') + iops = module.params.get('iops') device_name = module.params.get('device_name') region = module.params.get('region') zone = module.params.get('zone') @@ -155,12 +171,20 @@ def main(): if device_name: if device_name in inst.block_device_mapping: module.exit_json(msg="Volume mapping for %s already exists on instance %s" % (device_name, instance), + changed=False) + # If custom iops is defined we use volume_type "io1" rather than the default of "standard" + + if iops: + volume_type = 'io1' + else: + volume_type = 'standard' + # If no instance supplied, try volume creation based on module parameters. try: - volume = ec2.create_volume(volume_size, zone) + volume = ec2.create_volume(volume_size, zone, None, volume_type, iops) while volume.status != 'available': time.sleep(3) volume.update()