Skip to content

Commit

Permalink
add configuration_info
Browse files Browse the repository at this point in the history
  • Loading branch information
resmo committed Nov 25, 2024
1 parent 3ce1794 commit 5f316bc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type

DOCUMENTATION = '''
DOCUMENTATION = """
---
module: cs_configuration_info
module: configuration_info
short_description: Gathering information about configurations from Apache CloudStack based clouds.
description:
- Gathering information from the API about configurations.
author: Francisco Arencibia (@arencibiafrancisco)
version_added: 0.1.0
version_added: 3.0.0
options:
name:
description:
Expand All @@ -23,11 +24,11 @@
type: str
extends_documentation_fragment:
- ngine_io.cloudstack.cloudstack
'''
"""

EXAMPLES = '''
EXAMPLES = """
- name: Gather information about a specific configuration
ngine_io.cloudstack.cs_configuration_info:
ngine_io.cloudstack.configuration_info:
name: consoleproxy.sslEnabled
register: config
Expand All @@ -36,15 +37,15 @@
msg: "{{ config }}"
- name: Gather information about all configurations
ngine_io.cloudstack.cs_configuration_info:
ngine_io.cloudstack.configuration_info:
register: configs
- name: Show information on all configurations
debug:
msg: "{{ configs }}"
'''
"""

RETURN = '''
RETURN = """
---
configurations:
description: A list of matching configurations.
Expand All @@ -66,51 +67,48 @@
returned: success
type: str
sample: "Enable SSL for console proxy"
'''
"""

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.ngine_io.cloudstack.plugins.module_utils.cloudstack import (
AnsibleCloudStack,
cs_argument_spec,
)
from ansible_collections.ngine_io.cloudstack.plugins.module_utils.cloudstack import AnsibleCloudStack, cs_argument_spec


class AnsibleCloudStackConfigurationInfo(AnsibleCloudStack):

def __init__(self, module):
super(AnsibleCloudStackConfigurationInfo, self).__init__(module)
self.returns = {
'name': 'name',
'value': 'value',
'description': 'description',
"name": "name",
"value": "value",
"description": "description",
}

def get_configuration(self):
args = {}
if self.module.params['name']:
args['name'] = self.module.params['name']
configurations = self.query_api('listConfigurations', **args)
if configurations and 'configuration' in configurations:
configurations = configurations['configuration']
if self.module.params["name"]:
args["name"] = self.module.params["name"]
configurations = self.query_api("listConfigurations", **args)
if configurations and "configuration" in configurations:
configurations = configurations["configuration"]
else:
configurations = []
else:
configurations = self.query_api('listConfigurations')
if configurations and 'configuration' in configurations:
configurations = configurations['configuration']
configurations = self.query_api("listConfigurations")
if configurations and "configuration" in configurations:
configurations = configurations["configuration"]
else:
configurations = []

return {
'configurations': [self.update_result(config) for config in configurations]
}
return {"configurations": [self.update_result(config) for config in configurations]}


def main():
argument_spec = cs_argument_spec()
argument_spec.update(dict(
name=dict(type='str'),
))
argument_spec.update(
dict(
name=dict(type="str"),
)
)

module = AnsibleModule(
argument_spec=argument_spec,
Expand All @@ -122,5 +120,5 @@ def main():
module.exit_json(**result)


if __name__ == '__main__':
if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions tests/integration/targets/configuration_info/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cloud/cs
cs/group2
cs/group3
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: setup configuration is present
cs_configuration:
ngine_io.cloudstack.configuration:
name: consoleproxy.sslEnabled
value: true
register: config
Expand All @@ -10,10 +10,10 @@
- config is successful

- name: get info from configuration in check mode
cs_configuration_info:
ngine_io.cloudstack.configuration_info:
name: consoleproxy.sslEnabled
register: config_info
check_mode: yes
check_mode: true
- name: verify get info from configuration in check mode
assert:
that:
Expand All @@ -23,7 +23,7 @@
- config_info.configurations[0].value == "true"

- name: get info from configuration
cs_configuration_info:
ngine_io.cloudstack.configuration_info:
name: consoleproxy.sslEnabled
register: config_info
- name: verify get info from configuration
Expand All @@ -35,7 +35,7 @@
- config_info.configurations[0].value == "true"

- name: get info from all configurations
cs_configuration_info:
ngine_io.cloudstack.configuration_info:
register: configs
- name: verify get info from all configurations
assert:
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/targets/cs_configuration_info/aliases

This file was deleted.

0 comments on commit 5f316bc

Please sign in to comment.