Add resource group ID support for Aliyun VM allocation

- Introduced ALIYUN_RESOURCE_GROUP_ID environment variable to manage resource group assignments during VM allocation.
- Updated the _allocate_vm function to include resource group ID in the request if specified.
- Modified VNC URL logging to use public IP when available, enhancing clarity in access information.
- Maintained existing code logic while improving functionality for resource management and logging.
This commit is contained in:
Timothyxxx
2025-08-26 13:28:23 +08:00
parent 4c773f6f7c
commit ef2f35de22
2 changed files with 9 additions and 4 deletions

View File

@@ -39,6 +39,7 @@ ALIYUN_REGION = os.getenv("ALIYUN_REGION")
ALIYUN_IMAGE_ID = os.getenv("ALIYUN_IMAGE_ID")
ALIYUN_SECURITY_GROUP_ID = os.getenv("ALIYUN_SECURITY_GROUP_ID")
ALIYUN_VSWITCH_ID = os.getenv("ALIYUN_VSWITCH_ID")
ALIYUN_RESOURCE_GROUP_ID = os.getenv("ALIYUN_RESOURCE_GROUP_ID")
WAIT_DELAY = 20
MAX_ATTEMPTS = 15
@@ -139,6 +140,10 @@ def _allocate_vm(screen_size=(1920, 1080)):
),
deletion_protection=False,
)
if ALIYUN_RESOURCE_GROUP_ID:
kwargs["resource_group_id"] = ALIYUN_RESOURCE_GROUP_ID
if with_ttl and ttl_enabled and ttl_seconds > 0:
kwargs["auto_release_time"] = auto_release_str
return ecs_models.RunInstancesRequest(**kwargs)

View File

@@ -120,10 +120,10 @@ class AliyunProvider(Provider):
return ""
_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}")
if public_ip:
vnc_url = f"http://{public_ip}:5910/vnc.html"
logger.info(f"🖥️ VNC Web Access URL: {vnc_url}")
logger.info("=" * 80)
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}")