Add wait support to os_ironic_node

Add support for the os_ironic_node module to be capible of waiting
until the baremetal node activation or deactivation has completed.
This commit is contained in:
Julia Kreger 2016-01-17 17:42:46 -05:00
parent 7a0b488244
commit 9c7c9e8573

View file

@ -22,6 +22,8 @@ try:
except ImportError: except ImportError:
HAS_SHADE = False HAS_SHADE = False
from distutils.version import StrictVersion
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: os_ironic_node module: os_ironic_node
@ -96,6 +98,16 @@ options:
maintenance mode. maintenance mode.
required: false required: false
default: None default: None
wait:
description:
- A boolean value instructing the module to wait for node
activation or deactivation to complete before returning.
required: false
default: False
timeout:
description:
- An integer value representing the number of seconds to
wait for the node activation or deactivation to complete.
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -222,11 +234,19 @@ def main():
maintenance_reason=dict(required=False), maintenance_reason=dict(required=False),
power=dict(required=False, default='present'), power=dict(required=False, default='present'),
deploy=dict(required=False, default=True), deploy=dict(required=False, default=True),
wait=dict(type='bool', required=False, default=False),
timeout=dict(required=False, default=1800),
) )
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE: if not HAS_SHADE:
module.fail_json(msg='shade is required for this module') module.fail_json(msg='shade is required for this module')
if (module.params['wait'] and
StrictVersion(shade.__version__) < StrictVersion('1.4.0')):
module.fail_json(msg="To utilize wait, the installed version of"
"the shade library MUST be >=1.4.0")
if (module.params['auth_type'] in [None, 'None'] and if (module.params['auth_type'] in [None, 'None'] and
module.params['ironic_url'] is None): module.params['ironic_url'] is None):
module.fail_json(msg="Authentication appears disabled, Please " module.fail_json(msg="Authentication appears disabled, Please "
@ -253,6 +273,8 @@ def main():
uuid = node['uuid'] uuid = node['uuid']
instance_info = module.params['instance_info'] instance_info = module.params['instance_info']
changed = False changed = False
wait = module.params['wait']
timeout = module.params['timeout']
# User has reqeusted desired state to be in maintenance state. # User has reqeusted desired state to be in maintenance state.
if module.params['state'] is 'maintenance': if module.params['state'] is 'maintenance':
@ -305,17 +327,28 @@ def main():
patch = _prepare_instance_info_patch(instance_info) patch = _prepare_instance_info_patch(instance_info)
cloud.set_node_instance_info(uuid, patch) cloud.set_node_instance_info(uuid, patch)
cloud.validate_node(uuid) cloud.validate_node(uuid)
if not wait:
cloud.activate_node(uuid, module.params['config_drive']) cloud.activate_node(uuid, module.params['config_drive'])
# TODO(TheJulia): Add more error checking and a wait option. else:
# We will need to loop, or just add the logic to shade, cloud.activate_node(
# although this could be a very long running process as uuid,
# baremetal deployments are not a "quick" task. configdrive=module.params['config_drive'],
wait=wait,
timeout=timeout)
# TODO(TheJulia): Add more error checking..
module.exit_json(changed=changed, result="node activated") module.exit_json(changed=changed, result="node activated")
elif _is_false(module.params['state']): elif _is_false(module.params['state']):
if node['provision_state'] not in "deleted": if node['provision_state'] not in "deleted":
cloud.purge_node_instance_info(uuid) cloud.purge_node_instance_info(uuid)
if not wait:
cloud.deactivate_node(uuid) cloud.deactivate_node(uuid)
else:
cloud.deactivate_node(
uuid,
wait=wait,
timeout=timeout)
module.exit_json(changed=True, result="deleted") module.exit_json(changed=True, result="deleted")
else: else:
module.exit_json(changed=False, result="node not found") module.exit_json(changed=False, result="node not found")