-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new module cs_configuration_info (#130)
- Loading branch information
1 parent
3b335ac
commit 1fc49fc
Showing
4 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2024 | ||
# 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 = ''' | ||
--- | ||
module: cs_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 | ||
options: | ||
name: | ||
description: | ||
- Name of the configuration. | ||
- If not specified, information about all configurations is gathered. | ||
type: str | ||
extends_documentation_fragment: | ||
- ngine_io.cloudstack.cloudstack | ||
''' | ||
|
||
EXAMPLES = ''' | ||
- name: Gather information about a specific configuration | ||
ngine_io.cloudstack.cs_configuration_info: | ||
name: consoleproxy.sslEnabled | ||
register: config | ||
- name: Show the returned results of the registered variable | ||
debug: | ||
msg: "{{ config }}" | ||
- name: Gather information about all configurations | ||
ngine_io.cloudstack.cs_configuration_info: | ||
register: configs | ||
- name: Show information on all configurations | ||
debug: | ||
msg: "{{ configs }}" | ||
''' | ||
|
||
RETURN = ''' | ||
--- | ||
configurations: | ||
description: A list of matching configurations. | ||
type: list | ||
returned: success | ||
contains: | ||
name: | ||
description: Name of the configuration. | ||
returned: success | ||
type: str | ||
sample: consoleproxy.sslEnabled | ||
value: | ||
description: Value of the configuration. | ||
returned: success | ||
type: str | ||
sample: true | ||
description: | ||
description: Description of the configuration. | ||
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, | ||
) | ||
|
||
|
||
class AnsibleCloudStackConfigurationInfo(AnsibleCloudStack): | ||
|
||
def __init__(self, module): | ||
super(AnsibleCloudStackConfigurationInfo, self).__init__(module) | ||
self.returns = { | ||
'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'] | ||
else: | ||
configurations = [] | ||
else: | ||
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] | ||
} | ||
|
||
|
||
def main(): | ||
argument_spec = cs_argument_spec() | ||
argument_spec.update(dict( | ||
name=dict(type='str'), | ||
)) | ||
|
||
module = AnsibleModule( | ||
argument_spec=argument_spec, | ||
supports_check_mode=True, | ||
) | ||
|
||
acs_configuration_info = AnsibleCloudStackConfigurationInfo(module=module) | ||
result = acs_configuration_info.get_configuration() | ||
module.exit_json(**result) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cloud/cs | ||
shippable/cs/group2 | ||
shippable/cs/smoketest |
3 changes: 3 additions & 0 deletions
3
tests/integration/targets/cs_configuration_info/meta/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
dependencies: | ||
- cs_common |
47 changes: 47 additions & 0 deletions
47
tests/integration/targets/cs_configuration_info/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
- name: setup configuration is present | ||
cs_configuration: | ||
name: consoleproxy.sslEnabled | ||
value: true | ||
register: config | ||
- name: verify setup configuration is present | ||
assert: | ||
that: | ||
- config is successful | ||
|
||
- name: get info from configuration in check mode | ||
cs_configuration_info: | ||
name: consoleproxy.sslEnabled | ||
register: config_info | ||
check_mode: yes | ||
- name: verify get info from configuration in check mode | ||
assert: | ||
that: | ||
- config_info is successful | ||
- config_info is not changed | ||
- config_info.configurations[0].name == "consoleproxy.sslEnabled" | ||
- config_info.configurations[0].value == "true" | ||
|
||
- name: get info from configuration | ||
cs_configuration_info: | ||
name: consoleproxy.sslEnabled | ||
register: config_info | ||
- name: verify get info from configuration | ||
assert: | ||
that: | ||
- config_info is successful | ||
- config_info is not changed | ||
- config_info.configurations[0].name == "consoleproxy.sslEnabled" | ||
- config_info.configurations[0].value == "true" | ||
|
||
- name: get info from all configurations | ||
cs_configuration_info: | ||
register: configs | ||
- name: verify get info from all configurations | ||
assert: | ||
that: | ||
- configs is successful | ||
- configs is not changed | ||
- configs.configurations | length > 0 | ||
- '"name" in configs.configurations[0]' | ||
- '"value" in configs.configurations[0]' |