mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adding while loop to wait for cluster container creation (#4039)
* Adding while loop to wait * Adding changelog fragment * Adding parameter and more docs * Adjusting docs Co-authored-by: Travis Scotto <tscotto@webstaurantstore.com>
This commit is contained in:
parent
5fead8bbde
commit
7aab4497ac
3 changed files with 20 additions and 3 deletions
2
changelogs/fragments/4039-cluster-container-wait.yml
Normal file
2
changelogs/fragments/4039-cluster-container-wait.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- "lxc_container - added ``wait_for_container`` parameter. If ``true`` the module will wait until the running task reports success as the status (https://github.com/ansible-collections/community.general/pull/4039)."
|
|
@ -75,11 +75,14 @@ class LXDClient(object):
|
||||||
else:
|
else:
|
||||||
raise LXDClientException('URL scheme must be unix: or https:')
|
raise LXDClientException('URL scheme must be unix: or https:')
|
||||||
|
|
||||||
def do(self, method, url, body_json=None, ok_error_codes=None, timeout=None):
|
def do(self, method, url, body_json=None, ok_error_codes=None, timeout=None, wait_for_container=None):
|
||||||
resp_json = self._send_request(method, url, body_json=body_json, ok_error_codes=ok_error_codes, timeout=timeout)
|
resp_json = self._send_request(method, url, body_json=body_json, ok_error_codes=ok_error_codes, timeout=timeout)
|
||||||
if resp_json['type'] == 'async':
|
if resp_json['type'] == 'async':
|
||||||
url = '{0}/wait'.format(resp_json['operation'])
|
url = '{0}/wait'.format(resp_json['operation'])
|
||||||
resp_json = self._send_request('GET', url)
|
resp_json = self._send_request('GET', url)
|
||||||
|
if wait_for_container:
|
||||||
|
while resp_json['metadata']['status'] == 'Running':
|
||||||
|
resp_json = self._send_request('GET', url)
|
||||||
if resp_json['metadata']['status'] != 'Success':
|
if resp_json['metadata']['status'] != 'Success':
|
||||||
self._raise_err_from_json(resp_json)
|
self._raise_err_from_json(resp_json)
|
||||||
return resp_json
|
return resp_json
|
||||||
|
|
|
@ -124,6 +124,13 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
type: bool
|
type: bool
|
||||||
|
wait_for_container:
|
||||||
|
description:
|
||||||
|
- If set to C(true), the tasks will wait till the task reports a
|
||||||
|
success status when performing container operations.
|
||||||
|
default: false
|
||||||
|
type: bool
|
||||||
|
version_added: 4.4.0
|
||||||
force_stop:
|
force_stop:
|
||||||
description:
|
description:
|
||||||
- If this is true, the C(lxd_container) forces to stop the instance
|
- If this is true, the C(lxd_container) forces to stop the instance
|
||||||
|
@ -414,6 +421,7 @@ class LXDContainerManagement(object):
|
||||||
self.force_stop = self.module.params['force_stop']
|
self.force_stop = self.module.params['force_stop']
|
||||||
self.addresses = None
|
self.addresses = None
|
||||||
self.target = self.module.params['target']
|
self.target = self.module.params['target']
|
||||||
|
self.wait_for_container = self.module.params['wait_for_container']
|
||||||
|
|
||||||
self.type = self.module.params['type']
|
self.type = self.module.params['type']
|
||||||
|
|
||||||
|
@ -487,9 +495,9 @@ class LXDContainerManagement(object):
|
||||||
config = self.config.copy()
|
config = self.config.copy()
|
||||||
config['name'] = self.name
|
config['name'] = self.name
|
||||||
if self.target:
|
if self.target:
|
||||||
self.client.do('POST', '{0}?{1}'.format(self.api_endpoint, urlencode(dict(target=self.target))), config)
|
self.client.do('POST', '{0}?{1}'.format(self.api_endpoint, urlencode(dict(target=self.target))), config, wait_for_container=self.wait_for_container)
|
||||||
else:
|
else:
|
||||||
self.client.do('POST', self.api_endpoint, config)
|
self.client.do('POST', self.api_endpoint, config, wait_for_container=self.wait_for_container)
|
||||||
self.actions.append('create')
|
self.actions.append('create')
|
||||||
|
|
||||||
def _start_instance(self):
|
def _start_instance(self):
|
||||||
|
@ -745,6 +753,10 @@ def main():
|
||||||
default='container',
|
default='container',
|
||||||
choices=['container', 'virtual-machine'],
|
choices=['container', 'virtual-machine'],
|
||||||
),
|
),
|
||||||
|
wait_for_container=dict(
|
||||||
|
type='bool',
|
||||||
|
default=False
|
||||||
|
),
|
||||||
wait_for_ipv4_addresses=dict(
|
wait_for_ipv4_addresses=dict(
|
||||||
type='bool',
|
type='bool',
|
||||||
default=False
|
default=False
|
||||||
|
|
Loading…
Reference in a new issue