ReplaceSystemDisk
Replace the system disk of AlibabaCloud ECS instances in bulk to update or change the operating system using a specified Image ID.
Instructions
批量替换ECS实例的系统盘,更换操作系统
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ImageId | Yes | Image ID | |
| InstanceIds | Yes | AlibabaCloud ECS instance ID List | |
| RegionId | No | AlibabaCloud region ID | cn-hangzhou |
Implementation Reference
- The handler function OOS_ReplaceSystemDisk that implements the logic to replace system disks on multiple ECS instances using an OOS template.@tools.append def OOS_ReplaceSystemDisk( InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'), ImageId: str = Field(description='Image ID'), RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou') ): """批量替换ECS实例的系统盘,更换操作系统""" parameters = { 'regionId': RegionId, 'resourceType': 'ALIYUN::ECS::Instance', 'targets': { 'ResourceIds': InstanceIds, 'RegionId': RegionId, 'Type': 'ResourceIds' }, 'imageId': ImageId } return _start_execution_sync(region_id=RegionId, template_name='ACS-ECS-BulkyReplaceSystemDisk', parameters=parameters)
- Helper function that starts an OOS execution and polls until it reaches a terminal state, used by ReplaceSystemDisk 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)
- src/alibaba_cloud_ops_mcp_server/server.py:82-83 (registration)The registration loop that adds all tools from oos_tools.tools (including OOS_ReplaceSystemDisk) to the FastMCP server instance.for tool in oos_tools.tools: mcp.tool(tool)
- Pydantic input schema definition for the ReplaceSystemDisk tool parameters.InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'), ImageId: str = Field(description='Image ID'), RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou') ): """批量替换ECS实例的系统盘,更换操作系统""" parameters = { 'regionId': RegionId, 'resourceType': 'ALIYUN::ECS::Instance', 'targets': { 'ResourceIds': InstanceIds, 'RegionId': RegionId, 'Type': 'ResourceIds' }, 'imageId': ImageId } return _start_execution_sync(region_id=RegionId, template_name='ACS-ECS-BulkyReplaceSystemDisk', parameters=parameters)