start_ecs_instances
Initiate the startup of ECS instances on Alibaba Cloud by specifying the region and instance IDs, enabling efficient resource management and deployment.
Instructions
启动ECS实例
Args:
region: 区域ID,如cn-beijing
instance_ids: ECS实例ID列表
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instance_ids | No | ||
| region | No | cn-beijing |
Implementation Reference
- complete_fastmcp_server.py:329-351 (handler)MCP tool registration via @app.tool() and handler implementation. Dynamically imports oos_tools and invokes the matching helper function (OOS_StartInstances) to perform the ECS instance start operation using OOS templates.@app.tool() def start_ecs_instances(region: str = "cn-beijing", instance_ids: List[str] = None) -> str: """启动ECS实例 Args: region: 区域ID,如cn-beijing instance_ids: ECS实例ID列表 """ try: sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'alibaba_cloud_ops_mcp_server')) from tools import oos_tools if not instance_ids: return "请提供ECS实例ID列表" for tool_func in oos_tools.tools: if hasattr(tool_func, '__name__') and 'start' in tool_func.__name__.lower() and 'instance' in tool_func.__name__.lower(): result = tool_func(RegionId=region, InstanceIds=instance_ids) return str(result) return f"ECS实例启动功能可用,region: {region}, 实例: {instance_ids}" except Exception as e: return f"ECS实例启动失败: {str(e)}"
- Core helper function implementing the ECS instances start logic. Uses Alibaba Cloud OOS (Operation Orchestration Service) to execute the 'ACS-ECS-BulkyStartInstances' template on specified instances. Includes Pydantic Field definitions for input schema.@tools.append def OOS_StartInstances( InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'), RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'), ): """批量启动ECS实例,适用于需要同时管理和启动多台ECS实例的场景,例如应用部署和高可用性场景。""" parameters = { 'regionId': RegionId, 'resourceType': 'ALIYUN::ECS::Instance', 'targets': { 'ResourceIds': InstanceIds, 'RegionId': RegionId, 'Type': 'ResourceIds' } } return _start_execution_sync(region_id=RegionId, template_name='ACS-ECS-BulkyStartInstances', parameters=parameters)
- Supporting utility that synchronously starts an OOS execution for a given template and parameters, polls until completion, and handles errors. Used by OOS_StartInstances and other OOS tools.def _start_execution_sync(region_id: str, template_name: str, parameters: dict): client = create_client(region_id=region_id) start_execution_request = oos_20190601_models.StartExecutionRequest( region_id=region_id, template_name=template_name, parameters=json.dumps(parameters) ) start_execution_resp = client.start_execution(start_execution_request) execution_id = start_execution_resp.body.execution.execution_id while True: list_executions_request = oos_20190601_models.ListExecutionsRequest( region_id=region_id, execution_id=execution_id ) list_executions_resp = client.list_executions(list_executions_request) status = list_executions_resp.body.executions[0].status if status == FAILED: status_message = list_executions_resp.body.executions[0].status_message raise exception.OOSExecutionFailed(reason=status_message) elif status in END_STATUSES: return list_executions_resp.body time.sleep(1) @tools.append