2020-05-12 10:20:09 -05:00
|
|
|
#!/usr/bin/python
|
2022-07-28 09:19:14 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-05-12 10:20:09 -05:00
|
|
|
# Copyright (c) 2016 Hewlett-Packard Enterprise Corporation
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
2023-01-04 19:53:15 +01:00
|
|
|
DOCUMENTATION = r'''
|
2020-05-12 10:20:09 -05:00
|
|
|
---
|
|
|
|
module: project_info
|
|
|
|
short_description: Retrieve information about one or more OpenStack projects
|
2020-06-17 12:35:09 -05:00
|
|
|
author: OpenStack Ansible SIG
|
2020-05-12 10:20:09 -05:00
|
|
|
description:
|
2023-01-04 19:53:15 +01:00
|
|
|
- Retrieve information about a one or more OpenStack projects
|
2020-05-12 10:20:09 -05:00
|
|
|
options:
|
2023-01-04 19:53:15 +01:00
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- Name or ID of the project.
|
|
|
|
type: str
|
|
|
|
domain:
|
|
|
|
description:
|
|
|
|
- Name or ID of the domain containing the project.
|
|
|
|
type: str
|
|
|
|
filters:
|
|
|
|
description:
|
|
|
|
- A dictionary of meta data to use for filtering projects.
|
|
|
|
- Elements of I(filters) are passed as query parameters to
|
|
|
|
OpenStack Identity API.
|
|
|
|
type: dict
|
2020-05-12 10:20:09 -05:00
|
|
|
extends_documentation_fragment:
|
2023-01-04 19:53:15 +01:00
|
|
|
- openstack.cloud.openstack
|
2020-05-12 10:20:09 -05:00
|
|
|
'''
|
|
|
|
|
2023-01-04 19:53:15 +01:00
|
|
|
EXAMPLES = r'''
|
|
|
|
- name: Fetch all Identity (Keystone) projects
|
|
|
|
openstack.cloud.project_info:
|
2020-05-12 10:20:09 -05:00
|
|
|
cloud: awesomecloud
|
|
|
|
|
2023-01-04 19:53:15 +01:00
|
|
|
- name: Fetch all projects with a name
|
|
|
|
openstack.cloud.project_info:
|
2020-05-12 10:20:09 -05:00
|
|
|
cloud: awesomecloud
|
|
|
|
name: demoproject
|
|
|
|
|
2023-01-04 19:53:15 +01:00
|
|
|
- name: Fetch all projects with a name in a domain
|
|
|
|
openstack.cloud.project_info:
|
2020-05-12 10:20:09 -05:00
|
|
|
cloud: awesomecloud
|
|
|
|
name: demoproject
|
|
|
|
domain: admindomain
|
|
|
|
|
2023-01-04 19:53:15 +01:00
|
|
|
- name: Fetch all disabled projects
|
|
|
|
openstack.cloud.project_info:
|
2020-05-12 10:20:09 -05:00
|
|
|
cloud: awesomecloud
|
|
|
|
filters:
|
2023-01-04 19:53:15 +01:00
|
|
|
is_enabled: false
|
2020-05-12 10:20:09 -05:00
|
|
|
'''
|
|
|
|
|
2023-01-04 19:53:15 +01:00
|
|
|
RETURN = r'''
|
|
|
|
projects:
|
|
|
|
description: List of dictionaries describing Identity (Keystone) projects.
|
|
|
|
elements: dict
|
|
|
|
returned: always, but can be empty
|
|
|
|
type: list
|
|
|
|
contains:
|
|
|
|
description:
|
|
|
|
description: Project description
|
|
|
|
type: str
|
|
|
|
sample: "demodescription"
|
|
|
|
domain_id:
|
|
|
|
description: Domain ID to which the project belongs
|
|
|
|
type: str
|
|
|
|
sample: "default"
|
|
|
|
id:
|
|
|
|
description: Project ID
|
|
|
|
type: str
|
|
|
|
sample: "f59382db809c43139982ca4189404650"
|
|
|
|
is_domain:
|
|
|
|
description: Indicates whether the project also acts as a domain.
|
|
|
|
type: bool
|
|
|
|
is_enabled:
|
|
|
|
description: Indicates whether the project is enabled
|
|
|
|
type: bool
|
|
|
|
name:
|
|
|
|
description: Project name
|
|
|
|
type: str
|
|
|
|
sample: "demoproject"
|
|
|
|
options:
|
|
|
|
description: The resource options for the project
|
|
|
|
type: dict
|
|
|
|
parent_id:
|
|
|
|
description: The ID of the parent of the project
|
|
|
|
type: str
|
|
|
|
tags:
|
|
|
|
description: A list of associated tags
|
|
|
|
type: list
|
|
|
|
elements: str
|
2020-05-12 10:20:09 -05:00
|
|
|
'''
|
|
|
|
|
2021-05-05 13:25:46 +02:00
|
|
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
2020-05-12 10:20:09 -05:00
|
|
|
|
|
|
|
|
2021-05-05 13:25:46 +02:00
|
|
|
class IdentityProjectInfoModule(OpenStackModule):
|
|
|
|
argument_spec = dict(
|
2022-07-27 12:39:44 +02:00
|
|
|
domain=dict(),
|
2023-01-04 19:53:15 +01:00
|
|
|
name=dict(),
|
2022-07-27 12:39:44 +02:00
|
|
|
filters=dict(type='dict'),
|
2021-05-05 13:25:46 +02:00
|
|
|
)
|
|
|
|
module_kwargs = dict(
|
|
|
|
supports_check_mode=True
|
2020-05-12 10:20:09 -05:00
|
|
|
)
|
|
|
|
|
2021-05-05 13:25:46 +02:00
|
|
|
def run(self):
|
2022-03-14 16:08:53 +01:00
|
|
|
filters = self.params['filters'] or {}
|
2020-05-12 10:20:09 -05:00
|
|
|
|
2023-01-04 19:53:15 +01:00
|
|
|
domain_name_or_id = self.params['domain']
|
|
|
|
if domain_name_or_id is not None:
|
|
|
|
domain = self.conn.identity.find_domain(domain_name_or_id)
|
|
|
|
|
|
|
|
if not domain:
|
|
|
|
self.exit_json(changed=False, projects=[])
|
|
|
|
|
|
|
|
filters['domain_id'] = domain.id
|
2022-03-14 16:08:53 +01:00
|
|
|
|
2023-01-04 19:53:15 +01:00
|
|
|
projects = self.conn.search_projects(name_or_id=self.params['name'],
|
|
|
|
filters=filters)
|
2022-03-14 16:08:53 +01:00
|
|
|
|
2023-01-04 19:53:15 +01:00
|
|
|
self.exit_json(changed=False,
|
|
|
|
projects=[p.to_dict(computed=False) for p in projects])
|
2020-05-12 10:20:09 -05:00
|
|
|
|
2021-05-05 13:25:46 +02:00
|
|
|
|
|
|
|
def main():
|
|
|
|
module = IdentityProjectInfoModule()
|
|
|
|
module()
|
2020-05-12 10:20:09 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|