Add rudimentary wait for os_zone (#54391)

This adds a rudimentary wait functionality for the os_zone module.

It will wait for:
* Zone not in OpenStack API when choosing `absent`
* Zone `status` being `AVAILABLE` in OpenStack when choosing `present`
pull/58134/head
Stefan Prietl 6 years ago committed by ansibot
parent d0ee6e1e54
commit 9dbc838d99

@ -138,6 +138,25 @@ def _system_state_change(state, email, description, ttl, masters, zone):
return False return False
def _wait(timeout, cloud, zone, state, module, sdk):
"""Wait for a zone to reach the desired state for the given state."""
for count in sdk.utils.iterate_timeout(
timeout,
"Timeout waiting for zone to be %s" % state):
if (state == 'absent' and zone is None) or (state == 'present' and zone and zone.status == 'ACTIVE'):
return
try:
zone = cloud.get_zone(zone.id)
except Exception:
continue
if zone and zone.status == 'ERROR':
module.fail_json(msg="Zone reached ERROR state while waiting for it to be %s" % state)
def main(): def main():
argument_spec = openstack_full_argument_spec( argument_spec = openstack_full_argument_spec(
name=dict(required=True), name=dict(required=True),
@ -156,6 +175,8 @@ def main():
name = module.params.get('name') name = module.params.get('name')
state = module.params.get('state') state = module.params.get('state')
wait = module.params.get('wait')
timeout = module.params.get('timeout')
sdk, cloud = openstack_cloud_from_module(module) sdk, cloud = openstack_cloud_from_module(module)
try: try:
@ -191,6 +212,10 @@ def main():
name, email=email, name, email=email,
description=description, description=description,
ttl=ttl, masters=masters) ttl=ttl, masters=masters)
if wait:
_wait(timeout, cloud, zone, state, module, sdk)
module.exit_json(changed=changed, zone=zone) module.exit_json(changed=changed, zone=zone)
elif state == 'absent': elif state == 'absent':
@ -204,6 +229,10 @@ def main():
else: else:
cloud.delete_zone(name) cloud.delete_zone(name)
changed = True changed = True
if wait:
_wait(timeout, cloud, zone, state, module, sdk)
module.exit_json(changed=changed) module.exit_json(changed=changed)
except sdk.exceptions.OpenStackCloudException as e: except sdk.exceptions.OpenStackCloudException as e:

Loading…
Cancel
Save