From fcf824b4b6e926d9db1ddcf84d41aafaaa484d51 Mon Sep 17 00:00:00 2001
From: sguazt <marco.guazzone@gmail.com>
Date: Tue, 5 Jan 2021 11:26:38 +0100
Subject: [PATCH] OpenStack: use InstanceStatus instead of strings in node
 status map

---
 .../modules/openstack_openstacksdk/manager.py | 38 ++++++++++---------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/easycloud/modules/openstack_openstacksdk/manager.py b/easycloud/modules/openstack_openstacksdk/manager.py
index 0f7ec82..46df16c 100644
--- a/easycloud/modules/openstack_openstacksdk/manager.py
+++ b/easycloud/modules/openstack_openstacksdk/manager.py
@@ -24,24 +24,24 @@ class OpenStackInstance(Instance):
     """
 
     _NODE_STATUS_MAP = {
-        'BUILD': 'pending',
-        'REBUILD': 'pending',
-        'ACTIVE': 'running',
-        'SUSPENDED': 'suspended',
-        'SHUTOFF': 'stopped',
-        'DELETED': 'terminated',
-        'QUEUE_RESIZE': 'pending',
-        'PREP_RESIZE': 'pending',
-        'VERIFY_RESIZE': 'running',
-        'PASSWORD': 'pending',
-        'RESCUE': 'pending',
-        'REBOOT': 'rebooting',
-        'HARD_REBOOT': 'rebooting',
-        'SHARE_IP': 'pending',
-        'SHARE_IP_NO_CONFIG': 'pending',
-        'DELETE_IP': 'pending',
-        'ERROR': 'error',
-        'UNKNOWN': 'unknown'
+        'BUILD': InstanceStatus.PENDING,
+        'REBUILD': InstanceStatus.PENDING,
+        'ACTIVE': InstanceStatus.RUNNING,
+        'SUSPENDED': InstanceStatus.SUSPENDED,
+        'SHUTOFF': InstanceStatus.STOPPED,
+        'DELETED': InstanceStatus.TERMINATED,
+        'QUEUE_RESIZE': InstanceStatus.PENDING,
+        'PREP_RESIZE': InstanceStatus.PENDING,
+        'VERIFY_RESIZE': InstanceStatus.RUNNING,
+        'PASSWORD': InstanceStatus.PENDING,
+        'RESCUE': InstanceStatus.PENDING,
+        'REBOOT': InstanceStatus.REBOOTING,
+        'HARD_REBOOT': InstanceStatus.REBOOTING,
+        'SHARE_IP': InstanceStatus.PENDING,
+        'SHARE_IP_NO_CONFIG': InstanceStatus.PENDING,
+        'DELETE_IP': InstanceStatus.PENDING,
+        'ERROR': InstanceStatus.ERROR,
+        'UNKNOWN': InstanceStatus.UNKNOWN
     }
 
     def __init__(self, os_conn, os_instance):
@@ -88,9 +88,11 @@ class OpenStackInstance(Instance):
 
     def start(self):
         self._os_conn.compute.start_server(self._os_inst)
+        #TODO: call "self._os_conn.compute.wait_for_server(self._os_inst, status='ACTIVE', wait = timeout)" to perform a synchronous version of this method (note, if timeout is None you should invoke this method without the "wait" parameter, catching the "ResourceTimeout" exception and, in case such an exception is thrown, calling again the "wait_for_server()" method)
 
     def stop(self):
         self._os_conn.compute.stop_server(self._os_inst)
+        #TODO: call "self._os_conn.compute.wait_for_server(self._os_inst, status='ACTIVE', wait = timeout)" to perform a synchronous version of this method (note, if timeout is None you should invoke this method without the "wait" parameter, catching the "ResourceTimeout" exception and, in case such an exception is thrown, calling again the "wait_for_server()" method)
 
 
 class OpenStack(MetaManager):
-- 
GitLab