Clean code
This commit is contained in:
@@ -21,16 +21,16 @@ class AWSProviderWithProxy(Provider):
|
||||
super().__init__(region)
|
||||
self.current_proxy: Optional[ProxyInfo] = None
|
||||
|
||||
# 初始化代理池
|
||||
# Initialize proxy pool
|
||||
if proxy_config_file:
|
||||
init_proxy_pool(proxy_config_file)
|
||||
logger.info(f"Initialized proxy pool from {proxy_config_file}")
|
||||
|
||||
# 获取下一个可用代理
|
||||
# Get next available proxy
|
||||
self._rotate_proxy()
|
||||
|
||||
def _rotate_proxy(self):
|
||||
"""轮换到下一个可用代理"""
|
||||
"""Rotate to next available proxy"""
|
||||
proxy_pool = get_global_proxy_pool()
|
||||
self.current_proxy = proxy_pool.get_next_proxy()
|
||||
|
||||
@@ -40,7 +40,7 @@ class AWSProviderWithProxy(Provider):
|
||||
logger.warning("No proxy available, using direct connection")
|
||||
|
||||
def _generate_proxy_user_data(self) -> str:
|
||||
"""生成包含代理配置的user data脚本"""
|
||||
"""Generate user data script with proxy configuration"""
|
||||
if not self.current_proxy:
|
||||
return ""
|
||||
|
||||
@@ -107,7 +107,7 @@ echo "$(date): Configured proxy {self.current_proxy.host}:{self.current_proxy.po
|
||||
return base64.b64encode(user_data_script.encode()).decode()
|
||||
|
||||
def _format_proxy_url(self, proxy: ProxyInfo) -> str:
|
||||
"""格式化代理URL"""
|
||||
"""Format proxy URL"""
|
||||
if proxy.username and proxy.password:
|
||||
return f"{proxy.protocol}://{proxy.username}:{proxy.password}@{proxy.host}:{proxy.port}"
|
||||
else:
|
||||
@@ -118,7 +118,7 @@ echo "$(date): Configured proxy {self.current_proxy.host}:{self.current_proxy.po
|
||||
ec2_client = boto3.client('ec2', region_name=self.region)
|
||||
|
||||
try:
|
||||
# 如果实例已经存在,直接启动
|
||||
# If instance already exists, start it directly
|
||||
ec2_client.start_instances(InstanceIds=[path_to_vm])
|
||||
logger.info(f"Instance {path_to_vm} is starting...")
|
||||
|
||||
@@ -133,7 +133,7 @@ echo "$(date): Configured proxy {self.current_proxy.host}:{self.current_proxy.po
|
||||
|
||||
def create_instance_with_proxy(self, image_id: str, instance_type: str,
|
||||
security_groups: list, subnet_id: str) -> str:
|
||||
"""创建带有代理配置的新实例"""
|
||||
"""Create new instance with proxy configuration"""
|
||||
ec2_client = boto3.client('ec2', region_name=self.region)
|
||||
|
||||
user_data = self._generate_proxy_user_data()
|
||||
@@ -291,7 +291,7 @@ echo "$(date): Configured proxy {self.current_proxy.host}:{self.current_proxy.po
|
||||
raise
|
||||
|
||||
def get_current_proxy_info(self) -> Optional[dict]:
|
||||
"""获取当前代理信息"""
|
||||
"""Get current proxy information"""
|
||||
if self.current_proxy:
|
||||
return {
|
||||
'host': self.current_proxy.host,
|
||||
@@ -302,7 +302,7 @@ echo "$(date): Configured proxy {self.current_proxy.host}:{self.current_proxy.po
|
||||
return None
|
||||
|
||||
def force_rotate_proxy(self):
|
||||
"""强制轮换代理"""
|
||||
"""Force rotate proxy"""
|
||||
logger.info("Force rotating proxy...")
|
||||
if self.current_proxy:
|
||||
proxy_pool = get_global_proxy_pool()
|
||||
@@ -310,6 +310,6 @@ echo "$(date): Configured proxy {self.current_proxy.host}:{self.current_proxy.po
|
||||
self._rotate_proxy()
|
||||
|
||||
def get_proxy_stats(self) -> dict:
|
||||
"""获取代理池统计信息"""
|
||||
"""Get proxy pool statistics"""
|
||||
proxy_pool = get_global_proxy_pool()
|
||||
return proxy_pool.get_stats()
|
||||
Reference in New Issue
Block a user