Switch KeystoneFederationProtocolInfo module to OpenStackModule
Switch keystone federation_protocol_info module to the general OpenStackModule. Change-Id: Ia42c602ad7ea01dcb27d77370cc2617ec51aaaf3
This commit is contained in:
parent
6b3bf3bba0
commit
2120814356
@ -45,65 +45,53 @@ 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_protocol(protocol):
|
class IdentityFederationProtocolInfoModule(OpenStackModule):
|
||||||
"""
|
argument_spec = dict(
|
||||||
Normalizes the protocol definitions so that the outputs are consistent with the
|
|
||||||
parameters
|
|
||||||
|
|
||||||
- "name" (parameter) == "id" (SDK)
|
|
||||||
"""
|
|
||||||
if protocol is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
_protocol = protocol.to_dict()
|
|
||||||
_protocol['name'] = protocol['id']
|
|
||||||
# As of 0.44 SDK doesn't copy the URI parameters over, so let's add them
|
|
||||||
_protocol['idp_id'] = protocol['idp_id']
|
|
||||||
return _protocol
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
""" Module entry point """
|
|
||||||
|
|
||||||
argument_spec = openstack_full_argument_spec(
|
|
||||||
name=dict(aliases=['id']),
|
name=dict(aliases=['id']),
|
||||||
idp_id=dict(required=True, aliases=['idp_name']),
|
idp_id=dict(required=True, aliases=['idp_name']),
|
||||||
)
|
)
|
||||||
module_kwargs = openstack_module_kwargs(
|
module_kwargs = dict(
|
||||||
)
|
supports_check_mode=True
|
||||||
module = AnsibleModule(
|
|
||||||
argument_spec,
|
|
||||||
supports_check_mode=True,
|
|
||||||
**module_kwargs
|
|
||||||
)
|
)
|
||||||
|
|
||||||
name = module.params.get('name')
|
def normalize_protocol(self, protocol):
|
||||||
idp = module.params.get('idp_id')
|
"""
|
||||||
|
Normalizes the protocol definitions so that the outputs are consistent with the
|
||||||
|
parameters
|
||||||
|
|
||||||
sdk, cloud = openstack_cloud_from_module(module, min_version="0.44")
|
- "name" (parameter) == "id" (SDK)
|
||||||
|
"""
|
||||||
|
if protocol is None:
|
||||||
|
return None
|
||||||
|
|
||||||
if name:
|
_protocol = protocol.to_dict()
|
||||||
try:
|
_protocol['name'] = protocol['id']
|
||||||
protocol = cloud.identity.get_federation_protocol(idp, name)
|
# As of 0.44 SDK doesn't copy the URI parameters over, so let's add them
|
||||||
protocol = normalize_protocol(protocol)
|
_protocol['idp_id'] = protocol['idp_id']
|
||||||
except sdk.exceptions.ResourceNotFound:
|
return _protocol
|
||||||
module.fail_json(msg='Failed to find protocol')
|
|
||||||
except sdk.exceptions.OpenStackCloudException as ex:
|
|
||||||
module.fail_json(msg='Failed to get protocol: {0}'.format(str(ex)))
|
|
||||||
module.exit_json(changed=False, protocols=[protocol])
|
|
||||||
|
|
||||||
else:
|
def run(self):
|
||||||
try:
|
""" Module entry point """
|
||||||
protocols = list(map(normalize_protocol, cloud.identity.federation_protocols(idp)))
|
|
||||||
except sdk.exceptions.OpenStackCloudException as ex:
|
name = self.params.get('name')
|
||||||
module.fail_json(msg='Failed to list protocols: {0}'.format(str(ex)))
|
idp = self.params.get('idp_id')
|
||||||
module.exit_json(changed=False, protocols=protocols)
|
|
||||||
|
if name:
|
||||||
|
protocol = self.conn.identity.get_federation_protocol(idp, name)
|
||||||
|
protocol = self.normalize_protocol(protocol)
|
||||||
|
self.exit_json(changed=False, protocols=[protocol])
|
||||||
|
|
||||||
|
else:
|
||||||
|
protocols = list(map(self.normalize_protocol, self.conn.identity.federation_protocols(idp)))
|
||||||
|
self.exit_json(changed=False, protocols=protocols)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = IdentityFederationProtocolInfoModule()
|
||||||
|
module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user