Skip to content

Commit a996e8f

Browse files
authored
Remove INI config support (#64)
1 parent d76fa7c commit a996e8f

File tree

3 files changed

+24
-52
lines changed

3 files changed

+24
-52
lines changed

plugins/doc_fragments/cloudstack.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,42 @@ class ModuleDocFragment(object):
1616
description:
1717
- API key of the CloudStack API.
1818
- If not given, the C(CLOUDSTACK_KEY) env variable is considered.
19-
- As the last option, the value is taken from the ini config file, also see the notes.
2019
type: str
20+
required: true
2121
api_secret:
2222
description:
2323
- Secret key of the CloudStack API.
2424
- If not set, the C(CLOUDSTACK_SECRET) env variable is considered.
25-
- As the last option, the value is taken from the ini config file, also see the notes.
2625
type: str
26+
required: true
2727
api_url:
2828
description:
2929
- URL of the CloudStack API e.g. https://cloud.example.com/client/api.
3030
- If not given, the C(CLOUDSTACK_ENDPOINT) env variable is considered.
31-
- As the last option, the value is taken from the ini config file, also see the notes.
3231
type: str
32+
required: true
3333
api_http_method:
3434
description:
3535
- HTTP method used to query the API endpoint.
3636
- If not given, the C(CLOUDSTACK_METHOD) env variable is considered.
37-
- As the last option, the value is taken from the ini config file, also see the notes.
38-
- Fallback value is C(get) if not specified.
3937
type: str
4038
choices: [ get, post ]
39+
default: get
4140
api_timeout:
4241
description:
4342
- HTTP timeout in seconds.
4443
- If not given, the C(CLOUDSTACK_TIMEOUT) env variable is considered.
45-
- As the last option, the value is taken from the ini config file, also see the notes.
46-
- Fallback value is 10 seconds if not specified.
4744
type: int
48-
api_region:
49-
description:
50-
- Name of the ini section in the C(cloustack.ini) file.
51-
- If not given, the C(CLOUDSTACK_REGION) env variable is considered.
52-
type: str
53-
default: cloudstack
45+
default: 10
5446
api_verify_ssl_cert:
5547
description:
56-
- CA authority cert file.
48+
- Verify CA authority cert file.
5749
- If not given, the C(CLOUDSTACK_VERIFY) env variable is considered.
58-
- As the last option, the value is taken from the ini config file, also see the notes.
59-
- Fallback value is C(null) if not specified.
6050
type: str
6151
requirements:
6252
- python >= 2.6
6353
- cs >= 0.9.0
6454
notes:
65-
- Ansible uses the C(cs) library's configuration method if credentials are not
66-
provided by the arguments C(api_url), C(api_key), C(api_secret).
67-
Configuration is read from several locations, in the following order.
68-
The C(CLOUDSTACK_ENDPOINT), C(CLOUDSTACK_KEY), C(CLOUDSTACK_SECRET) and
69-
C(CLOUDSTACK_METHOD). C(CLOUDSTACK_TIMEOUT) environment variables.
70-
A C(CLOUDSTACK_CONFIG) environment variable pointing to an C(.ini) file.
71-
A C(cloudstack.ini) file in the current working directory.
72-
A C(.cloudstack.ini) file in the users home directory.
73-
Optionally multiple credentials and endpoints can be specified using ini sections in C(cloudstack.ini).
74-
Use the argument C(api_region) to select the section name, default section is C(cloudstack).
75-
See https://github.com/exoscale/cs for more information.
7655
- A detailed guide about cloudstack modules can be found in the L(CloudStack Cloud Guide,../scenario_guides/guide_cloudstack.html).
7756
- This module supports check mode.
7857
'''
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
breaking_changes:
2+
- Authentication option using INI files e.g. ``cloudstack.ini`` has been removed. The only supported option to authenticate
3+
is by using the module params with fallback to the ENV variables.

plugins/module_utils/cloudstack.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import traceback
1313

1414
from ansible.module_utils._text import to_text, to_native
15-
from ansible.module_utils.basic import missing_required_lib
15+
from ansible.module_utils.basic import missing_required_lib, env_fallback
1616

1717
CS_IMP_ERR = None
1818
try:
19-
from cs import CloudStack, CloudStackException, read_config
19+
from cs import CloudStack, CloudStackException
2020
HAS_LIB_CS = True
2121
except ImportError:
2222
CS_IMP_ERR = traceback.format_exc()
@@ -29,18 +29,17 @@
2929

3030
def cs_argument_spec():
3131
return dict(
32-
api_key=dict(default=os.environ.get('CLOUDSTACK_KEY')),
33-
api_secret=dict(default=os.environ.get('CLOUDSTACK_SECRET'), no_log=True),
34-
api_url=dict(default=os.environ.get('CLOUDSTACK_ENDPOINT')),
35-
api_http_method=dict(choices=['get', 'post'], default=os.environ.get('CLOUDSTACK_METHOD')),
36-
api_timeout=dict(type='int', default=os.environ.get('CLOUDSTACK_TIMEOUT')),
37-
api_region=dict(default=os.environ.get('CLOUDSTACK_REGION') or 'cloudstack'),
38-
api_verify_ssl_cert=dict(default=os.environ.get('CLOUDSTACK_VERIFY')),
32+
api_key=dict(type='str', fallback=(env_fallback, ['CLOUDSTACK_KEY']), required=True),
33+
api_secret=dict(type='str', fallback=(env_fallback, ['CLOUDSTACK_SECRET']), required=True, no_log=True),
34+
api_url=dict(type='str', fallback=(env_fallback, ['CLOUDSTACK_ENDPOINT']), required=True),
35+
api_http_method=dict(type='str', fallback=(env_fallback, ['CLOUDSTACK_METHOD']), choices=['get', 'post'], default='get'),
36+
api_timeout=dict(type='int', fallback=(env_fallback, ['CLOUDSTACK_TIMEOUT']), default=10),
37+
api_verify_ssl_cert=dict(type='str', fallback=(env_fallback, ['CLOUDSTACK_VERIFY'])),
3938
)
4039

4140

4241
def cs_required_together():
43-
return [['api_key', 'api_secret']]
42+
return []
4443

4544

4645
class AnsibleCloudStack:
@@ -114,30 +113,21 @@ def cs(self):
114113
return self._cs
115114

116115
def get_api_config(self):
117-
api_region = self.module.params.get('api_region') or os.environ.get('CLOUDSTACK_REGION')
118-
try:
119-
config = read_config(api_region)
120-
except KeyError:
121-
config = {}
122-
123116
api_config = {
124-
'endpoint': self.module.params.get('api_url') or config.get('endpoint'),
125-
'key': self.module.params.get('api_key') or config.get('key'),
126-
'secret': self.module.params.get('api_secret') or config.get('secret'),
127-
'timeout': self.module.params.get('api_timeout') or config.get('timeout') or 10,
128-
'method': self.module.params.get('api_http_method') or config.get('method') or 'get',
129-
'verify': self.module.params.get('api_verify_ssl_cert') or config.get('verify'),
117+
'endpoint': self.module.params.get('api_url'),
118+
'key': self.module.params.get('api_key'),
119+
'secret': self.module.params.get('api_secret'),
120+
'timeout': self.module.params.get('api_timeout'),
121+
'method': self.module.params.get('api_http_method'),
122+
'verify': self.module.params.get('api_verify_ssl_cert'),
130123
}
131124
self.result.update({
132-
'api_region': api_region,
133125
'api_url': api_config['endpoint'],
134126
'api_key': api_config['key'],
135127
'api_timeout': int(api_config['timeout']),
136128
'api_http_method': api_config['method'],
137129
'api_verify_ssl_cert': api_config['verify'],
138130
})
139-
if not all([api_config['endpoint'], api_config['key'], api_config['secret']]):
140-
self.fail_json(msg="Missing api credentials: can not authenticate")
141131
return api_config
142132

143133
def fail_json(self, **kwargs):

0 commit comments

Comments
 (0)