cloudstack: fix timeout in ini config file is ignored (#34833)
* cloudstack: fix timeout in ini config file is ignored * cloudstack: prepare for unit tests
This commit is contained in:
parent
9302e8d2a4
commit
1c3bba0bdb
1 changed files with 14 additions and 7 deletions
|
@ -39,8 +39,8 @@ def cs_argument_spec():
|
||||||
api_key=dict(default=os.environ.get('CLOUDSTACK_KEY')),
|
api_key=dict(default=os.environ.get('CLOUDSTACK_KEY')),
|
||||||
api_secret=dict(default=os.environ.get('CLOUDSTACK_SECRET'), no_log=True),
|
api_secret=dict(default=os.environ.get('CLOUDSTACK_SECRET'), no_log=True),
|
||||||
api_url=dict(default=os.environ.get('CLOUDSTACK_ENDPOINT')),
|
api_url=dict(default=os.environ.get('CLOUDSTACK_ENDPOINT')),
|
||||||
api_http_method=dict(choices=['get', 'post'], default=os.environ.get('CLOUDSTACK_METHOD') or 'get'),
|
api_http_method=dict(choices=['get', 'post'], default=os.environ.get('CLOUDSTACK_METHOD')),
|
||||||
api_timeout=dict(type='int', default=os.environ.get('CLOUDSTACK_TIMEOUT') or 10),
|
api_timeout=dict(type='int', default=os.environ.get('CLOUDSTACK_TIMEOUT')),
|
||||||
api_region=dict(default=os.environ.get('CLOUDSTACK_REGION') or 'cloudstack'),
|
api_region=dict(default=os.environ.get('CLOUDSTACK_REGION') or 'cloudstack'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ class AnsibleCloudStack:
|
||||||
]
|
]
|
||||||
|
|
||||||
self.module = module
|
self.module = module
|
||||||
self._connect()
|
self._cs = None
|
||||||
|
|
||||||
# Helper for VPCs
|
# Helper for VPCs
|
||||||
self._vpc_networks_ids = None
|
self._vpc_networks_ids = None
|
||||||
|
@ -111,7 +111,14 @@ class AnsibleCloudStack:
|
||||||
self.capabilities = None
|
self.capabilities = None
|
||||||
self.network_acl = None
|
self.network_acl = None
|
||||||
|
|
||||||
def _connect(self):
|
@property
|
||||||
|
def cs(self):
|
||||||
|
if self._cs is None:
|
||||||
|
api_config = self.get_api_config()
|
||||||
|
self._cs = CloudStack(**api_config)
|
||||||
|
return self._cs
|
||||||
|
|
||||||
|
def get_api_config(self):
|
||||||
api_region = self.module.params.get('api_region') or os.environ.get('CLOUDSTACK_REGION')
|
api_region = self.module.params.get('api_region') or os.environ.get('CLOUDSTACK_REGION')
|
||||||
try:
|
try:
|
||||||
config = read_config(api_region)
|
config = read_config(api_region)
|
||||||
|
@ -122,8 +129,8 @@ class AnsibleCloudStack:
|
||||||
'endpoint': self.module.params.get('api_url') or config.get('endpoint'),
|
'endpoint': self.module.params.get('api_url') or config.get('endpoint'),
|
||||||
'key': self.module.params.get('api_key') or config.get('key'),
|
'key': self.module.params.get('api_key') or config.get('key'),
|
||||||
'secret': self.module.params.get('api_secret') or config.get('secret'),
|
'secret': self.module.params.get('api_secret') or config.get('secret'),
|
||||||
'timeout': self.module.params.get('api_timeout') or config.get('timeout'),
|
'timeout': self.module.params.get('api_timeout') or config.get('timeout') or 10,
|
||||||
'method': self.module.params.get('api_http_method') or config.get('method'),
|
'method': self.module.params.get('api_http_method') or config.get('method') or 'get',
|
||||||
}
|
}
|
||||||
self.result.update({
|
self.result.update({
|
||||||
'api_region': api_region,
|
'api_region': api_region,
|
||||||
|
@ -134,7 +141,7 @@ class AnsibleCloudStack:
|
||||||
})
|
})
|
||||||
if not all([api_config['endpoint'], api_config['key'], api_config['secret']]):
|
if not all([api_config['endpoint'], api_config['key'], api_config['secret']]):
|
||||||
self.fail_json(msg="Missing api credentials: can not authenticate")
|
self.fail_json(msg="Missing api credentials: can not authenticate")
|
||||||
self.cs = CloudStack(**api_config)
|
return api_config
|
||||||
|
|
||||||
def fail_json(self, **kwargs):
|
def fail_json(self, **kwargs):
|
||||||
self.result.update(kwargs)
|
self.result.update(kwargs)
|
||||||
|
|
Loading…
Reference in a new issue