Merge "Switch federation_mapping_info module to OpenStackModule"
This commit is contained in:
commit
b9df964149
|
@ -38,13 +38,20 @@ EXAMPLES = '''
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import openstack_full_argument_spec
|
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import openstack_module_kwargs
|
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import openstack_cloud_from_module
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_mapping(mapping):
|
class IdentityFederationMappingInfoModule(OpenStackModule):
|
||||||
|
argument_spec = dict(
|
||||||
|
name=dict(aliases=['id']),
|
||||||
|
)
|
||||||
|
module_kwargs = dict(
|
||||||
|
supports_check_mode=True
|
||||||
|
)
|
||||||
|
|
||||||
|
module_min_sdk_version = "0.44"
|
||||||
|
|
||||||
|
def normalize_mapping(self, mapping):
|
||||||
"""
|
"""
|
||||||
Normalizes the mapping definitions so that the outputs are consistent with the
|
Normalizes the mapping definitions so that the outputs are consistent with the
|
||||||
parameters
|
parameters
|
||||||
|
@ -58,40 +65,23 @@ def normalize_mapping(mapping):
|
||||||
_mapping['name'] = mapping['id']
|
_mapping['name'] = mapping['id']
|
||||||
return _mapping
|
return _mapping
|
||||||
|
|
||||||
|
def run(self):
|
||||||
def main():
|
|
||||||
""" Module entry point """
|
""" Module entry point """
|
||||||
|
name = self.params.get('name')
|
||||||
argument_spec = openstack_full_argument_spec(
|
|
||||||
name=dict(aliases=['id']),
|
|
||||||
)
|
|
||||||
module_kwargs = openstack_module_kwargs(
|
|
||||||
)
|
|
||||||
module = AnsibleModule(
|
|
||||||
argument_spec,
|
|
||||||
supports_check_mode=True,
|
|
||||||
**module_kwargs
|
|
||||||
)
|
|
||||||
|
|
||||||
name = module.params.get('name')
|
|
||||||
|
|
||||||
sdk, cloud = openstack_cloud_from_module(module, min_version="0.44")
|
|
||||||
|
|
||||||
if name:
|
if name:
|
||||||
try:
|
mapping = self.normalize_mapping(
|
||||||
mapping = normalize_mapping(cloud.identity.get_mapping(name))
|
self.conn.identity.get_mapping(name))
|
||||||
except sdk.exceptions.ResourceNotFound:
|
self.exit_json(changed=False, mappings=[mapping])
|
||||||
module.fail_json(msg='Failed to find mapping')
|
|
||||||
except sdk.exceptions.OpenStackCloudException as ex:
|
|
||||||
module.fail_json(msg='Failed to get mapping: {0}'.format(str(ex)))
|
|
||||||
module.exit_json(changed=False, mappings=[mapping])
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
mappings = list(map(
|
||||||
mappings = list(map(normalize_mapping, cloud.identity.mappings()))
|
self.normalize_mapping, self.conn.identity.mappings()))
|
||||||
except sdk.exceptions.OpenStackCloudException as ex:
|
self.exit_json(changed=False, mappings=mappings)
|
||||||
module.fail_json(msg='Failed to list mappings: {0}'.format(str(ex)))
|
|
||||||
module.exit_json(changed=False, mappings=mappings)
|
|
||||||
|
def main():
|
||||||
|
module = IdentityFederationMappingInfoModule()
|
||||||
|
module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue