1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Jakub Jursa 2017-07-04 11:51:07 +02:00 committed by Ricardo Carrillo Cruz
parent ad3fe08aae
commit 5fafe4c672

View file

@ -75,6 +75,12 @@ options:
description: description:
- Ignored. Present for backwards compatibility - Ignored. Present for backwards compatibility
required: false required: false
scheduler_hints:
description:
- Scheduler hints passed to volume API in form of dict
required: false
default: None
version_added: "2.4"
requirements: requirements:
- "python >= 2.6" - "python >= 2.6"
- "shade" - "shade"
@ -92,6 +98,8 @@ EXAMPLES = '''
availability_zone: az2 availability_zone: az2
size: 40 size: 40
display_name: test_volume display_name: test_volume
scheduler_hints:
same_host: 243e8d3c-8f47-4a61-93d6-7215c344b0c0
''' '''
try: try:
@ -100,6 +108,8 @@ try:
except ImportError: except ImportError:
HAS_SHADE = False HAS_SHADE = False
from distutils.version import StrictVersion
def _present_volume(module, cloud): def _present_volume(module, cloud):
if cloud.volume_exists(module.params['display_name']): 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']) module.fail_json(msg="Failed to find volume '%s'" % module.params['volume'])
volume_args['source_volid'] = volume_id volume_args['source_volid'] = volume_id
if module.params['scheduler_hints']:
volume_args['scheduler_hints'] = module.params['scheduler_hints']
volume = cloud.create_volume( volume = cloud.create_volume(
wait=module.params['wait'], timeout=module.params['timeout'], wait=module.params['wait'], timeout=module.params['timeout'],
**volume_args) **volume_args)
@ -153,6 +166,7 @@ def main():
snapshot_id=dict(default=None), snapshot_id=dict(default=None),
volume=dict(default=None), volume=dict(default=None),
state=dict(default='present', choices=['absent', 'present']), state=dict(default='present', choices=['absent', 'present']),
scheduler_hints=dict(default=None, type='dict')
) )
module_kwargs = openstack_module_kwargs( module_kwargs = openstack_module_kwargs(
mutually_exclusive=[ mutually_exclusive=[
@ -164,6 +178,11 @@ def main():
if not HAS_SHADE: if not HAS_SHADE:
module.fail_json(msg='shade is required for this module') 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'] state = module.params['state']
if state == 'present' and not module.params['size']: if state == 'present' and not module.params['size']: