Skip to content

Commit 1fc49fc

Browse files
new module cs_configuration_info (#130)
1 parent 3b335ac commit 1fc49fc

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2024
5+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6+
7+
from __future__ import absolute_import, division, print_function
8+
__metaclass__ = type
9+
10+
DOCUMENTATION = '''
11+
---
12+
module: cs_configuration_info
13+
short_description: Gathering information about configurations from Apache CloudStack based clouds.
14+
description:
15+
- Gathering information from the API about configurations.
16+
author: Francisco Arencibia (@arencibiafrancisco)
17+
version_added: 0.1.0
18+
options:
19+
name:
20+
description:
21+
- Name of the configuration.
22+
- If not specified, information about all configurations is gathered.
23+
type: str
24+
extends_documentation_fragment:
25+
- ngine_io.cloudstack.cloudstack
26+
'''
27+
28+
EXAMPLES = '''
29+
- name: Gather information about a specific configuration
30+
ngine_io.cloudstack.cs_configuration_info:
31+
name: consoleproxy.sslEnabled
32+
register: config
33+
34+
- name: Show the returned results of the registered variable
35+
debug:
36+
msg: "{{ config }}"
37+
38+
- name: Gather information about all configurations
39+
ngine_io.cloudstack.cs_configuration_info:
40+
register: configs
41+
42+
- name: Show information on all configurations
43+
debug:
44+
msg: "{{ configs }}"
45+
'''
46+
47+
RETURN = '''
48+
---
49+
configurations:
50+
description: A list of matching configurations.
51+
type: list
52+
returned: success
53+
contains:
54+
name:
55+
description: Name of the configuration.
56+
returned: success
57+
type: str
58+
sample: consoleproxy.sslEnabled
59+
value:
60+
description: Value of the configuration.
61+
returned: success
62+
type: str
63+
sample: true
64+
description:
65+
description: Description of the configuration.
66+
returned: success
67+
type: str
68+
sample: "Enable SSL for console proxy"
69+
'''
70+
71+
from ansible.module_utils.basic import AnsibleModule
72+
from ansible_collections.ngine_io.cloudstack.plugins.module_utils.cloudstack import (
73+
AnsibleCloudStack,
74+
cs_argument_spec,
75+
)
76+
77+
78+
class AnsibleCloudStackConfigurationInfo(AnsibleCloudStack):
79+
80+
def __init__(self, module):
81+
super(AnsibleCloudStackConfigurationInfo, self).__init__(module)
82+
self.returns = {
83+
'name': 'name',
84+
'value': 'value',
85+
'description': 'description',
86+
}
87+
88+
def get_configuration(self):
89+
args = {}
90+
if self.module.params['name']:
91+
args['name'] = self.module.params['name']
92+
configurations = self.query_api('listConfigurations', **args)
93+
if configurations and 'configuration' in configurations:
94+
configurations = configurations['configuration']
95+
else:
96+
configurations = []
97+
else:
98+
configurations = self.query_api('listConfigurations')
99+
if configurations and 'configuration' in configurations:
100+
configurations = configurations['configuration']
101+
else:
102+
configurations = []
103+
104+
return {
105+
'configurations': [self.update_result(config) for config in configurations]
106+
}
107+
108+
109+
def main():
110+
argument_spec = cs_argument_spec()
111+
argument_spec.update(dict(
112+
name=dict(type='str'),
113+
))
114+
115+
module = AnsibleModule(
116+
argument_spec=argument_spec,
117+
supports_check_mode=True,
118+
)
119+
120+
acs_configuration_info = AnsibleCloudStackConfigurationInfo(module=module)
121+
result = acs_configuration_info.get_configuration()
122+
module.exit_json(**result)
123+
124+
125+
if __name__ == '__main__':
126+
main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cloud/cs
2+
shippable/cs/group2
3+
shippable/cs/smoketest
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
dependencies:
3+
- cs_common
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
- name: setup configuration is present
3+
cs_configuration:
4+
name: consoleproxy.sslEnabled
5+
value: true
6+
register: config
7+
- name: verify setup configuration is present
8+
assert:
9+
that:
10+
- config is successful
11+
12+
- name: get info from configuration in check mode
13+
cs_configuration_info:
14+
name: consoleproxy.sslEnabled
15+
register: config_info
16+
check_mode: yes
17+
- name: verify get info from configuration in check mode
18+
assert:
19+
that:
20+
- config_info is successful
21+
- config_info is not changed
22+
- config_info.configurations[0].name == "consoleproxy.sslEnabled"
23+
- config_info.configurations[0].value == "true"
24+
25+
- name: get info from configuration
26+
cs_configuration_info:
27+
name: consoleproxy.sslEnabled
28+
register: config_info
29+
- name: verify get info from configuration
30+
assert:
31+
that:
32+
- config_info is successful
33+
- config_info is not changed
34+
- config_info.configurations[0].name == "consoleproxy.sslEnabled"
35+
- config_info.configurations[0].value == "true"
36+
37+
- name: get info from all configurations
38+
cs_configuration_info:
39+
register: configs
40+
- name: verify get info from all configurations
41+
assert:
42+
that:
43+
- configs is successful
44+
- configs is not changed
45+
- configs.configurations | length > 0
46+
- '"name" in configs.configurations[0]'
47+
- '"value" in configs.configurations[0]'

0 commit comments

Comments
 (0)