retire shade in favor of openstacksdk for openstack modules (#40532)

* Establish connection through openstacksdk
* Switch from shade to openstacksdk
* fix typo in link to openstacksdk
* remove nova_client usage
* further remove of min_version from openstack modules
This commit is contained in:
Artem Goncharov 2018-05-26 03:40:39 +02:00 committed by Monty Taylor
commit 89ce826a9f
51 changed files with 266 additions and 321 deletions

View file

@ -60,7 +60,7 @@ options:
- Ignored. Present for backwards compatibility
requirements:
- "python >= 2.6"
- "shade"
- "openstacksdk"
'''
EXAMPLES = '''
---
@ -152,7 +152,7 @@ from ansible.module_utils.openstack import openstack_full_argument_spec, opensta
from ansible.module_utils._text import to_native
def _create_stack(module, stack, cloud, shade):
def _create_stack(module, stack, cloud, sdk):
try:
stack = cloud.create_stack(module.params['name'],
tags=module.params['tag'],
@ -168,14 +168,14 @@ def _create_stack(module, stack, cloud, shade):
return stack
else:
module.fail_json(msg="Failure in creating stack: {0}".format(stack))
except shade.OpenStackCloudException as e:
except sdk.exceptions.OpenStackCloudException as e:
if hasattr(e, 'response'):
module.fail_json(msg=to_native(e), response=e.response.json())
else:
module.fail_json(msg=to_native(e))
def _update_stack(module, stack, cloud, shade):
def _update_stack(module, stack, cloud, sdk):
try:
stack = cloud.update_stack(
module.params['name'],
@ -191,7 +191,7 @@ def _update_stack(module, stack, cloud, shade):
else:
module.fail_json(msg="Failure in updating stack: %s" %
stack['stack_status_reason'])
except shade.OpenStackCloudException as e:
except sdk.exceptions.OpenStackCloudException as e:
if hasattr(e, 'response'):
module.fail_json(msg=to_native(e), response=e.response.json())
else:
@ -226,13 +226,6 @@ def main():
supports_check_mode=True,
**module_kwargs)
# stack API introduced in 1.8.0
min_version = '1.8.0'
tag = module.params['tag']
if tag is not None:
# stack tag API was introduced in 1.26.0
min_version = '1.26.0'
state = module.params['state']
name = module.params['name']
# Check for required parameters when state == 'present'
@ -241,7 +234,7 @@ def main():
if not module.params[p]:
module.fail_json(msg='%s required with present state' % p)
shade, cloud = openstack_cloud_from_module(module, min_version='1.26.0')
sdk, cloud = openstack_cloud_from_module(module)
try:
stack = cloud.get_stack(name)
@ -251,9 +244,9 @@ def main():
if state == 'present':
if not stack:
stack = _create_stack(module, stack, cloud, shade)
stack = _create_stack(module, stack, cloud, sdk)
else:
stack = _update_stack(module, stack, cloud, shade)
stack = _update_stack(module, stack, cloud, sdk)
changed = True
module.exit_json(changed=changed,
stack=stack,
@ -266,7 +259,7 @@ def main():
if not cloud.delete_stack(name, wait=module.params['wait']):
module.fail_json(msg='delete stack failed for stack: %s' % name)
module.exit_json(changed=changed)
except shade.OpenStackCloudException as e:
except sdk.exceptions.OpenStackCloudException as e:
module.fail_json(msg=to_native(e))