From 5fafe4c672097cc4da1a3138f4107e56650c80a7 Mon Sep 17 00:00:00 2001 From: Jakub Jursa Date: Tue, 4 Jul 2017 11:51:07 +0200 Subject: [PATCH] openstack: os_volume: add optional scheduler_hints param (#26090) * openstack: os_volume: add optional scheduler_hints param * openstack: os_volume: scheduler_hints version_added fix * openstack: os_volume: fixed codestyle --- .../modules/cloud/openstack/os_volume.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/ansible/modules/cloud/openstack/os_volume.py b/lib/ansible/modules/cloud/openstack/os_volume.py index 736ce242eb..50ee3083fc 100644 --- a/lib/ansible/modules/cloud/openstack/os_volume.py +++ b/lib/ansible/modules/cloud/openstack/os_volume.py @@ -75,6 +75,12 @@ options: description: - Ignored. Present for backwards compatibility required: false + scheduler_hints: + description: + - Scheduler hints passed to volume API in form of dict + required: false + default: None + version_added: "2.4" requirements: - "python >= 2.6" - "shade" @@ -92,6 +98,8 @@ EXAMPLES = ''' availability_zone: az2 size: 40 display_name: test_volume + scheduler_hints: + same_host: 243e8d3c-8f47-4a61-93d6-7215c344b0c0 ''' try: @@ -100,6 +108,8 @@ try: except ImportError: HAS_SHADE = False +from distutils.version import StrictVersion + def _present_volume(module, cloud): if cloud.volume_exists(module.params['display_name']): @@ -124,6 +134,9 @@ def _present_volume(module, cloud): module.fail_json(msg="Failed to find volume '%s'" % module.params['volume']) volume_args['source_volid'] = volume_id + if module.params['scheduler_hints']: + volume_args['scheduler_hints'] = module.params['scheduler_hints'] + volume = cloud.create_volume( wait=module.params['wait'], timeout=module.params['timeout'], **volume_args) @@ -153,6 +166,7 @@ def main(): snapshot_id=dict(default=None), volume=dict(default=None), state=dict(default='present', choices=['absent', 'present']), + scheduler_hints=dict(default=None, type='dict') ) module_kwargs = openstack_module_kwargs( mutually_exclusive=[ @@ -164,6 +178,11 @@ def main(): if not HAS_SHADE: module.fail_json(msg='shade is required for this module') + if (module.params['scheduler_hints'] and + StrictVersion(shade.__version__) < StrictVersion('1.22')): + module.fail_json(msg="To utilize scheduler_hints, the installed version of" + "the shade library MUST be >= 1.22") + state = module.params['state'] if state == 'present' and not module.params['size']: