| 
					
				 | 
			
			
				@@ -1,5 +1,5 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import time 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import requests 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import utils 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import logging 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import os 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -52,6 +52,29 @@ start_sh = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+def server_health_check(instance_id, health_check_url): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    服务健康检查 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    :param instance_id: instanceId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    :param health_check_url: 服务健康检查url 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    :return: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ip_address = get_ip_address(client=client, instance_id=instance_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    while True: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        health_url = f"http://{ip_address}:5001/healthcheck" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            http_code = requests.get(health_check_url).status_code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        except: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logging.info("images is downloading") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            http_code = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if http_code == 200: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            time.sleep(20) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def ess_instance(create_client, slb_client, ess_count): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     扩容机器并运行新服务 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -73,6 +96,10 @@ def ess_instance(create_client, slb_client, ess_count): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     server_start_sh = os.path.join(start_sh['target_dir'], start_sh['name']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     server_start_commend = f"sh {server_start_sh}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     utils.run_command(client=create_client, instance_ids=ess_instance_ids, command=server_start_commend) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 4. 探活 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    health_instance_ids = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def main(): 
			 |