|
@@ -57,29 +57,31 @@ def remove_instances(ecs_client, alb_client, instance_ids, port):
|
|
|
# sys.exit()
|
|
|
|
|
|
# 4. 判断机器运行状态是否为 Stopped
|
|
|
- while True:
|
|
|
- response = utils.get_instances_status(ecs_client=ecs_client, instance_ids=instance_ids)
|
|
|
- if response.get('Code') is None:
|
|
|
- instances_list = response.get('InstanceStatuses').get('InstanceStatus')
|
|
|
- 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(stopped_instances)}, instances: {stopped_instances}")
|
|
|
- time.sleep(5)
|
|
|
- else:
|
|
|
- logging.error(response)
|
|
|
- sys.exit()
|
|
|
+ stopped_instances = utils.get_instances_status(ecs_client=ecs_client, instance_ids=instance_ids)
|
|
|
+ # while True:
|
|
|
+ # response = utils.get_instances_status(ecs_client=ecs_client, instance_ids=instance_ids)
|
|
|
+ # if response.get('Code') is None:
|
|
|
+ # instances_list = response.get('InstanceStatuses').get('InstanceStatus')
|
|
|
+ # 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(stopped_instances)}, instances: {stopped_instances}")
|
|
|
+ # time.sleep(5)
|
|
|
+ # else:
|
|
|
+ # logging.error(response)
|
|
|
+ # sys.exit()
|
|
|
|
|
|
# 5. 释放机器
|
|
|
- release_response = utils.release_instances(ecs_client=ecs_client, instance_ids=stopped_instances)
|
|
|
- if release_response.get('Code') is None:
|
|
|
- logging.info(f"Release instances finished, instances: {stopped_instances}")
|
|
|
- else:
|
|
|
- logging.error(f"Release instances fail!!!")
|
|
|
- sys.exit()
|
|
|
+ utils.release_instances(ecs_client=ecs_client, instance_ids=stopped_instances)
|
|
|
+ # release_response = utils.release_instances(ecs_client=ecs_client, instance_ids=stopped_instances)
|
|
|
+ # if release_response.get('Code') is None:
|
|
|
+ # logging.info(f"Release instances finished, instances: {stopped_instances}")
|
|
|
+ # else:
|
|
|
+ # logging.error(f"Release instances fail!!!")
|
|
|
+ # sys.exit()
|
|
|
|
|
|
|
|
|
def main():
|