
Be consistent with Ansible docs [1], [2], [3].
[1] https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_documenting.html
[2] https://docs.ansible.com/ansible-core/devel/dev_guide/testing/sanity/shebang.html
[3] b86a18bd27/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py
Change-Id: Ia3976bb3fcca662cefa219edeef057bcb7143c01
91 lines
2.2 KiB
Python
91 lines
2.2 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright: Ansible Project
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
DOCUMENTATION = '''
|
|
---
|
|
module: federation_mapping_info
|
|
short_description: Get the information about the available federation mappings
|
|
author: OpenStack Ansible SIG
|
|
description:
|
|
- Fetch a federation mapping.
|
|
options:
|
|
name:
|
|
description:
|
|
- The name of the mapping to fetch.
|
|
- If I(name) is specified, the module will return failed if the mapping
|
|
doesn't exist.
|
|
type: str
|
|
aliases: ['id']
|
|
requirements:
|
|
- "python >= 3.6"
|
|
- "openstacksdk >= 0.44"
|
|
extends_documentation_fragment:
|
|
- openstack.cloud.openstack
|
|
'''
|
|
|
|
EXAMPLES = '''
|
|
- name: Fetch a specific mapping
|
|
openstack.cloud.federation_mapping_info:
|
|
cloud: example_cloud
|
|
name: example_mapping
|
|
|
|
- name: Fetch all mappings
|
|
openstack.cloud.federation_mapping_info:
|
|
cloud: example_cloud
|
|
'''
|
|
|
|
RETURN = '''
|
|
'''
|
|
|
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
|
|
|
|
|
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
|
|
parameters
|
|
|
|
- "name" (parameter) == "id" (SDK)
|
|
"""
|
|
if mapping is None:
|
|
return None
|
|
|
|
_mapping = mapping.to_dict()
|
|
_mapping['name'] = mapping['id']
|
|
return _mapping
|
|
|
|
def run(self):
|
|
""" Module entry point """
|
|
name = self.params.get('name')
|
|
|
|
if name:
|
|
mapping = self.normalize_mapping(
|
|
self.conn.identity.get_mapping(name))
|
|
self.exit_json(changed=False, mappings=[mapping])
|
|
else:
|
|
mappings = list(map(
|
|
self.normalize_mapping, self.conn.identity.mappings()))
|
|
self.exit_json(changed=False, mappings=mappings)
|
|
|
|
|
|
def main():
|
|
module = IdentityFederationMappingInfoModule()
|
|
module()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|