Add Aliyun SDK dependencies and implement TTL configuration for ECS instances
- Added new dependencies for Aliyun ECS SDK in requirements.txt and setup.py to support instance management features. - Introduced a new config module to handle TTL settings for ECS instances, allowing for auto-termination based on environment variables. - Updated the manager to utilize TTL settings, including scheduling instance termination with proper error handling and logging. - Maintained existing code logic while enhancing functionality for improved instance lifecycle management.
This commit is contained in:
@@ -24,6 +24,11 @@ class AliyunProvider(Provider):
|
||||
super().__init__(**kwargs)
|
||||
self.region = os.getenv("ALIYUN_REGION", "eu-central-1")
|
||||
self.client = self._create_client()
|
||||
# Whether to use private IP instead of public IP. Default: enabled.
|
||||
# Priority: explicit kwarg > env var ALIYUN_USE_PRIVATE_IP > default True
|
||||
env_use_private = os.getenv("ALIYUN_USE_PRIVATE_IP", "1").lower() in {"1", "true", "yes", "on"}
|
||||
kw_flag = kwargs.get("use_private_ip", None)
|
||||
self.use_private_ip = env_use_private if kw_flag is None else bool(kw_flag)
|
||||
|
||||
def _create_client(self) -> ECSClient:
|
||||
config = open_api_models.Config(
|
||||
@@ -107,24 +112,29 @@ class AliyunProvider(Provider):
|
||||
if hasattr(instance, "eip_address") and instance.eip_address:
|
||||
public_ip = instance.eip_address.ip_address or public_ip
|
||||
|
||||
_wait_until_server_ready(public_ip)
|
||||
# Select which IP to use based on configuration
|
||||
ip_to_use = private_ip if (self.use_private_ip and private_ip) else public_ip
|
||||
|
||||
if public_ip:
|
||||
vnc_url = f"http://{public_ip}:5910/vnc.html"
|
||||
logger.info("=" * 80)
|
||||
logger.info(f"🖥️ VNC Web Access URL: {vnc_url}")
|
||||
logger.info(f"📡 Public IP: {public_ip}")
|
||||
logger.info(f"🏠 Private IP: {private_ip}")
|
||||
logger.info("=" * 80)
|
||||
print(f"\n🌐 VNC Web Access URL: {vnc_url}")
|
||||
print(
|
||||
"📍 Please open the above address in the browser "
|
||||
"for remote desktop access\n"
|
||||
)
|
||||
else:
|
||||
logger.warning("No public IP address available for VNC access")
|
||||
if not ip_to_use:
|
||||
logger.warning("No usable IP address available (private/public both missing)")
|
||||
return ""
|
||||
|
||||
return public_ip
|
||||
_wait_until_server_ready(ip_to_use)
|
||||
|
||||
vnc_url = f"http://{ip_to_use}:5910/vnc.html"
|
||||
logger.info("=" * 80)
|
||||
logger.info(f"🖥️ VNC Web Access URL: {vnc_url}")
|
||||
logger.info(f"📡 Public IP: {public_ip}")
|
||||
logger.info(f"🏠 Private IP: {private_ip}")
|
||||
logger.info(f"🔧 Using IP: {'Private' if ip_to_use == private_ip else 'Public'} -> {ip_to_use}")
|
||||
logger.info("=" * 80)
|
||||
print(f"\n🌐 VNC Web Access URL: {vnc_url}")
|
||||
print(
|
||||
"📍 Please open the above address in the browser "
|
||||
"for remote desktop access\n"
|
||||
)
|
||||
|
||||
return ip_to_use
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
|
||||
Reference in New Issue
Block a user