| 
					
				 | 
			
			
				@@ -10,22 +10,6 @@ from concurrent.futures import ThreadPoolExecutor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 health_instances = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-def pull_image(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    """从镜像仓库中拉取指定版本的镜像""" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    instanceId = q1.get() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    ipaddr = utils_alb.get_ip_address(ecs_client, instanceId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    cd_url = "tcp://{}:2375".format(ipaddr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    client = docker.DockerClient(base_url=cd_url, timeout=30) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        client.images.pull(repository.format(apps), tag=version)  # 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print(ipaddr, "pull images success ") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return True 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    except Exception as e: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print(e, "images pull fail") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return False 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def gateway_health_check(ecs_client, instance_id, max_wait_time=None): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     服务健康检查 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -36,7 +20,7 @@ def gateway_health_check(ecs_client, instance_id, max_wait_time=None): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     global health_instances 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     start_time = time.time() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    ip_address = utils_alb.get_ip_address(ecs_client=ecs_client, instance_id=instance_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ip_address = alb_utils.get_ip_address(ecs_client=ecs_client, instance_id=instance_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     while True: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         health_check_url = f"http://{ip_address}:9000/healthcheck" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try: 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -71,7 +55,7 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, port): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     :return: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # 1. 购买机器并启动 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    ess_instance_ids = utils_alb.create_multiple_instances( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ess_instance_ids = alb_utils.create_multiple_instances( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         amount=ess_count, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ecs_client=ecs_client, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         **gateway_config.instance_config_j, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -79,13 +63,13 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, port): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     time.sleep(60) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # 2. 发送启动脚本到机器上 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    utils_alb.send_file_to_ecs(ecs_client=ecs_client, instance_id_list=ess_instance_ids, **gateway_config.start_sh) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    alb_utils.send_file_to_ecs(ecs_client=ecs_client, instance_id_list=ess_instance_ids, **gateway_config.start_sh) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     logging.info(f"send start shell file finished, count: {len(ess_instance_ids)} instances: {ess_instance_ids}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # 3. 启动服务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     start_sh_param = "latest" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     server_start_sh = os.path.join(gateway_config.start_sh['target_dir'], gateway_config.start_sh['name']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     server_start_commend = f"sh {server_start_sh} {start_sh_param}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    utils_alb.run_command(ecs_client=ecs_client, instance_ids=ess_instance_ids, command=server_start_commend) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    alb_utils.run_command(ecs_client=ecs_client, instance_ids=ess_instance_ids, command=server_start_commend) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     # 4. 异步探活 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     global health_instances 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     health_instances = [] 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -108,7 +92,7 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, port): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         #     instance_id_list.append(instance_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         # #     for server_group_id in gateway_config.server_group_id_list: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         health_instance_ids = [instance_id for instance_id, _ in health_instances] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        utils_alb.add_servers_to_server_group(alb_client, gateway_config.server_group_id_list, health_instance_ids, weight=100, port=port) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        alb_utils.add_servers_to_server_group(alb_client, gateway_config.server_group_id_list, health_instance_ids, weight=100, port=port) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         logging.info(f"ess count: {ess_count}, " 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                      f"create count: {len(ess_instance_ids)}, " 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                      f"finished count: {len(health_instances)}") 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -122,10 +106,10 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, port): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def main(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        ecs_client = utils_alb.connect_client(access_key_id=gateway_config.ecs_client_params['access_key_id'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ecs_client = alb_utils.connect_client(access_key_id=gateway_config.ecs_client_params['access_key_id'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                           access_key_secret=gateway_config.ecs_client_params['access_key_secret'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                           region_id=gateway_config.ecs_client_params['region_id']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        alb_client = utils_alb.connect_alb_client( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        alb_client = alb_utils.connect_alb_client( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             access_key_id=gateway_config.alb_client_params['access_key_id'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             access_key_secret=gateway_config.alb_client_params['access_key_secret'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             endpoint=gateway_config.alb_client_params['endpoint'] 
			 |