mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-07 05:43:15 +00:00
Refactored project{,_info} modules
Change-Id: I863d08c42b4c708444b74e3d47f0ca70a8ff94fd
This commit is contained in:
@@ -4,117 +4,97 @@
|
||||
# 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)
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: project_info
|
||||
short_description: Retrieve information about one or more OpenStack projects
|
||||
author: OpenStack Ansible SIG
|
||||
description:
|
||||
- Retrieve information about a one or more OpenStack projects
|
||||
- Retrieve information about a one or more OpenStack projects
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
- Name or ID of the project
|
||||
type: str
|
||||
domain:
|
||||
description:
|
||||
- Name or ID of the domain containing the project if the cloud supports domains
|
||||
type: str
|
||||
filters:
|
||||
description:
|
||||
- A dictionary of meta data to use for filtering projects. Elements of
|
||||
this dictionary are parsed as queries for openstack identity api in
|
||||
the new openstacksdk.
|
||||
type: dict
|
||||
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
|
||||
requirements:
|
||||
- "python >= 3.6"
|
||||
- "openstacksdk"
|
||||
|
||||
- "python >= 3.6"
|
||||
- "openstacksdk"
|
||||
extends_documentation_fragment:
|
||||
- openstack.cloud.openstack
|
||||
- openstack.cloud.openstack
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
# Gather information about previously created projects
|
||||
- openstack.cloud.project_info:
|
||||
EXAMPLES = r'''
|
||||
- name: Fetch all Identity (Keystone) projects
|
||||
openstack.cloud.project_info:
|
||||
cloud: awesomecloud
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.openstack_projects }}"
|
||||
|
||||
# Gather information about a previously created project by name
|
||||
- openstack.cloud.project_info:
|
||||
- name: Fetch all projects with a name
|
||||
openstack.cloud.project_info:
|
||||
cloud: awesomecloud
|
||||
name: demoproject
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.openstack_projects }}"
|
||||
|
||||
# Gather information about a previously created project in a specific domain
|
||||
- openstack.cloud.project_info:
|
||||
- name: Fetch all projects with a name in a domain
|
||||
openstack.cloud.project_info:
|
||||
cloud: awesomecloud
|
||||
name: demoproject
|
||||
domain: admindomain
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.openstack_projects }}"
|
||||
|
||||
# Gather information about a previously created project in a specific domain with filter
|
||||
- openstack.cloud.project_info:
|
||||
- name: Fetch all disabled projects
|
||||
openstack.cloud.project_info:
|
||||
cloud: awesomecloud
|
||||
name: demoproject
|
||||
domain: admindomain
|
||||
filters:
|
||||
is_enabled: False
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.openstack_projects }}"
|
||||
is_enabled: false
|
||||
'''
|
||||
|
||||
|
||||
RETURN = '''
|
||||
openstack_projects:
|
||||
description: has all the OpenStack information about projects
|
||||
elements: dict
|
||||
returned: always, but can be empty
|
||||
type: list
|
||||
contains:
|
||||
id:
|
||||
description: Unique UUID.
|
||||
returned: success
|
||||
type: str
|
||||
name:
|
||||
description: Name given to the project.
|
||||
returned: success
|
||||
type: str
|
||||
description:
|
||||
description: Description of the project
|
||||
returned: success
|
||||
type: str
|
||||
is_enabled:
|
||||
description: Flag to indicate if the project is enabled
|
||||
returned: success
|
||||
type: bool
|
||||
domain_id:
|
||||
description: Domain ID containing the project (keystone v3 clouds only)
|
||||
returned: success
|
||||
type: bool
|
||||
tags:
|
||||
description: A list of simple strings assigned to a project
|
||||
returned: success
|
||||
type: list
|
||||
parent_id:
|
||||
description: The ID of the parent for the project
|
||||
returned: success
|
||||
type: str
|
||||
is_domain:
|
||||
description: Indicates whether the project also acts as a domain.
|
||||
returned: success
|
||||
type: bool
|
||||
options:
|
||||
description: Set of options for the project
|
||||
returned: success
|
||||
type: dict
|
||||
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
|
||||
'''
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||
@@ -122,8 +102,8 @@ from ansible_collections.openstack.cloud.plugins.module_utils.openstack import O
|
||||
|
||||
class IdentityProjectInfoModule(OpenStackModule):
|
||||
argument_spec = dict(
|
||||
name=dict(),
|
||||
domain=dict(),
|
||||
name=dict(),
|
||||
filters=dict(type='dict'),
|
||||
)
|
||||
module_kwargs = dict(
|
||||
@@ -131,18 +111,22 @@ class IdentityProjectInfoModule(OpenStackModule):
|
||||
)
|
||||
|
||||
def run(self):
|
||||
name = self.params['name']
|
||||
domain = self.params['domain']
|
||||
filters = self.params['filters'] or {}
|
||||
|
||||
if domain:
|
||||
filters['domain_id'] = self.conn.identity.find_domain(
|
||||
domain, ignore_missing=False).id
|
||||
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)
|
||||
|
||||
projects = self.conn.search_projects(name, filters=filters)
|
||||
projects = [p.to_dict(computed=False) for p in projects]
|
||||
if not domain:
|
||||
self.exit_json(changed=False, projects=[])
|
||||
|
||||
self.exit_json(changed=False, openstack_projects=projects)
|
||||
filters['domain_id'] = domain.id
|
||||
|
||||
projects = self.conn.search_projects(name_or_id=self.params['name'],
|
||||
filters=filters)
|
||||
|
||||
self.exit_json(changed=False,
|
||||
projects=[p.to_dict(computed=False) for p in projects])
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user