From fd15087c4ddb3d6c62ffd94702b795367d4578e0 Mon Sep 17 00:00:00 2001
From: Dmitry Tantsur <dtantsur@protonmail.com>
Date: Wed, 13 Jul 2022 11:21:32 +0200
Subject: [PATCH] Add a wait argument to baremetal_node

openstacksdk will start using cleaning in 1.0.0 [1], so we need to be
able to wait for it to finish.

[1] https://review.opendev.org/c/openstack/openstacksdk/+/849402

Change-Id: I9695b1a5acfa007ad474c9b5b07a4fdb4c1b1198
---
 plugins/modules/baremetal_node.py | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/plugins/modules/baremetal_node.py b/plugins/modules/baremetal_node.py
index 1adb560..9a7d141 100644
--- a/plugins/modules/baremetal_node.py
+++ b/plugins/modules/baremetal_node.py
@@ -164,6 +164,18 @@ options:
       type: bool
       aliases:
         - skip_update_of_driver_password
+    wait:
+      description:
+        - A boolean value instructing the module to wait for the newly created
+          node to reach the available state.
+      type: bool
+      default: 'no'
+    timeout:
+      description:
+        - An integer value representing the number of seconds to
+          wait for the newly created node to reach the available state.
+      default: 1800
+      type: int
 requirements:
     - "python >= 3.6"
     - "openstacksdk"
@@ -304,7 +316,9 @@ def main():
                 version='2.0.0',
                 collection_name='openstack.cloud')]
         ),
-        state=dict(required=False, default='present', choices=['present', 'absent'])
+        state=dict(required=False, default='present', choices=['present', 'absent']),
+        wait=dict(type='bool', required=False, default=False),
+        timeout=dict(required=False, type='int', default=1800),
     )
     module_kwargs = openstack_module_kwargs()
     module = IronicModule(argument_spec, **module_kwargs)
@@ -358,8 +372,11 @@ def main():
                 if module.params['uuid']:
                     kwargs['uuid'] = module.params['uuid']
 
-                server = cloud.register_machine(module.params['nics'],
-                                                **kwargs)
+                server = cloud.register_machine(
+                    module.params['nics'],
+                    wait=module.params['wait'],
+                    timeout=module.params['timeout'],
+                    **kwargs)
                 module.exit_json(changed=True, uuid=server['uuid'],
                                  provision_state=server['provision_state'])
             else:
-- 
GitLab