liqian 2 years ago
parent
commit
37e3b756e6
1 changed files with 14 additions and 12 deletions
  1. 14 12
      rov_server_update.py

+ 14 - 12
rov_server_update.py

@@ -301,20 +301,22 @@ def remove_instances(create_client, slb_client, instance_ids):
     utils.stop_instances(client=create_client, instance_ids=instance_ids)
     logging.info(f"instances stop finished, instances: {instance_ids}")
     # 3. 判断机器运行状态是否为Stopped
-    response = utils.get_instances_status(client=create_client, instance_ids=instance_ids)
-    if response.get('Code') is None:
-        instances_list = response.get('InstanceStatuses').get('InstanceStatus')
-        logging.info(instances_list)
-        stopped_instances = [instance.get('InstanceId') for instance in instances_list
-                             if instance.get('Status') == 'Stopped']
-        if len(stopped_instances) == len(instance_ids):
-            logging.info(f"instances stopped status set success, instances: {stopped_instances}")
+    while True:
+        response = utils.get_instances_status(client=create_client, instance_ids=instance_ids)
+        if response.get('Code') is None:
+            instances_list = response.get('InstanceStatuses').get('InstanceStatus')
+            logging.info(instances_list)
+            stopped_instances = [instance.get('InstanceId') for instance in instances_list
+                                 if instance.get('Status') == 'Stopped']
+            if len(stopped_instances) == len(instance_ids):
+                logging.info(f"instances stopped status set success, instances: {stopped_instances}")
+                break
+            else:
+                logging.info(f"stopped instances count = {len(instance_ids)}, instances: {stopped_instances}")
+                time.sleep(10)
         else:
-            logging.info(f"stopped instances count = {len(instance_ids)}, instances: {stopped_instances}")
+            logging.error(response)
             sys.exit()
-    else:
-        logging.error(response)
-        sys.exit()
     # 4. 释放机器
     response = utils.release_instances(client=create_client, instance_ids=stopped_instances)
     if response.get('Code') is None: