os_keystone_mapping: fixup some minor nits found in followup reviews
Change-Id: I0c8995e8d52a993395e674c06c84f6398473754c
This commit is contained in:
parent
bf4af7b1b9
commit
54c189063f
@ -85,23 +85,22 @@ RETURN = '''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import openstack_full_argument_spec
|
||||||
openstack_full_argument_spec,
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import openstack_module_kwargs
|
||||||
openstack_module_kwargs,
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import openstack_cloud_from_module
|
||||||
openstack_cloud_from_module)
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_mapping(mapping):
|
def normalize_mapping(mapping):
|
||||||
"""
|
"""
|
||||||
Normalizes the mapping definitions so that the outputs are consistent with the
|
Normalizes the mapping definitions so that the outputs are consistent with
|
||||||
parameters
|
the parameters
|
||||||
|
|
||||||
- "name" (parameter) == "id" (SDK)
|
- "name" (parameter) == "id" (SDK)
|
||||||
"""
|
"""
|
||||||
if mapping is None:
|
if mapping is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
_mapping = dict(mapping)
|
_mapping = mapping.to_dict()
|
||||||
_mapping['name'] = mapping['id']
|
_mapping['name'] = mapping['id']
|
||||||
return _mapping
|
return _mapping
|
||||||
|
|
||||||
@ -198,12 +197,16 @@ def main():
|
|||||||
mapping = cloud.identity.get_mapping(name)
|
mapping = cloud.identity.get_mapping(name)
|
||||||
except sdk.exceptions.ResourceNotFound:
|
except sdk.exceptions.ResourceNotFound:
|
||||||
mapping = None
|
mapping = None
|
||||||
|
except sdk.exceptions.OpenStackCloudException as ex:
|
||||||
|
module.fail_json(msg='Failed to fetch mapping: {0}'.format(str(ex)))
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
if mapping is not None:
|
if mapping is not None:
|
||||||
changed = delete_mapping(module, sdk, cloud, mapping)
|
changed = delete_mapping(module, sdk, cloud, mapping)
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed)
|
||||||
|
|
||||||
|
# state == 'present'
|
||||||
|
else:
|
||||||
if len(module.params.get('rules')) < 1:
|
if len(module.params.get('rules')) < 1:
|
||||||
module.fail_json(msg='At least one rule must be passed')
|
module.fail_json(msg='At least one rule must be passed')
|
||||||
|
|
||||||
@ -211,7 +214,7 @@ def main():
|
|||||||
(changed, mapping) = create_mapping(module, sdk, cloud, name)
|
(changed, mapping) = create_mapping(module, sdk, cloud, name)
|
||||||
mapping = normalize_mapping(mapping)
|
mapping = normalize_mapping(mapping)
|
||||||
module.exit_json(changed=changed, mapping=mapping)
|
module.exit_json(changed=changed, mapping=mapping)
|
||||||
|
else:
|
||||||
(changed, new_mapping) = update_mapping(module, sdk, cloud, mapping)
|
(changed, new_mapping) = update_mapping(module, sdk, cloud, mapping)
|
||||||
new_mapping = normalize_mapping(new_mapping)
|
new_mapping = normalize_mapping(new_mapping)
|
||||||
module.exit_json(mapping=new_mapping, changed=changed)
|
module.exit_json(mapping=new_mapping, changed=changed)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user