弹性云服务器挂载磁盘
场景描述
弹性云服务器创建成功后,如果发现磁盘不够用或当前磁盘不满足要求,可以将已有磁盘挂载给弹性云服务器,或调用创建云硬盘的接口创建新的磁盘,然后再挂载至弹性云服务器。挂载操作需要调用挂载云硬盘接口。
您可以在创建云服务器时,通过设置“data_volumes”参数值挂载数据盘,也可以在创建云服务器成功后挂载数据盘。本节主要介绍云服务器创建成功后挂载磁盘的场景。
操作步骤
- 创建云硬盘。
- 创建云硬盘。
- 接口相关信息
URI格式:POST /v2/{project_id}/volumes
详情请参见创建云硬盘。
- 请求示例
POST https://{endpoint}/v2/74610f3a5ad941998e91f076297ecf27/volumes
{endpoint}信息请从地区和终端节点获取。
Body:
{ "volume": { "name": "openapi_vol02", "availability_zone":"az_test_01", "description": "create for api test", "volume_type": "SSD", "size": 40 } }
- 响应示例
{ "volume": { "status": "creating", "user_id": "f79791beca3c48159ac2553fff22e166", "attachments": [], "links": [ { "href": "https://xxx/v2/74610f3a5ad941998e91f076297ecf27/volumes/51f45e08-1d4f-44c6-a4a9-84a488e0e8d3", "rel": "self" }, { "href": "https://xxx/74610f3a5ad941998e91f076297ecf27/volumes/51f45e08-1d4f-44c6-a4a9-84a488e0e8d3", "rel": "bookmark" } ], "availability_zone": "az_test_01", "bootable": "false", "encrypted": false, "created_at": "2018-05-16T11:19:33.992984", "description": "create for api test", "updated_at": null, "volume_type": "SSD", "name": "openapi_vol02", "replication_status": "disabled", "consistencygroup_id": null, "source_volid": null, "snapshot_id": null, "shareable": false, "multiattach": false, "metadata": { "__system__volume_name": "openapi_vol02" }, "id": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3", "size": 40 } }
- 接口相关信息
- 记录响应中“volume”的ID。
- 创建云硬盘。
- 挂载磁盘。
- 接口相关信息
URI格式:POST /v1/{project_id}/cloudservers/{server_id}/attachvolume
详情请参见弹性云服务器挂载磁盘。
- 请求示例
POST https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/cloudservers/9f4d9281-95e7-4915-a126-1ee597101e2e/attachvolume
{endpoint}信息请从地区和终端节点获取。
Body:
{ "volumeAttachment": { "volumeId": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3", "device": "/dev/sdb", "volume_type": "SSD", "count": 5, "hw:passthrough": "true" }, "dry_run": false }
- 响应示例
{ "job_id": "ff80808288d41e1b018990260955686a" }
- 接口相关信息
- 确认挂载磁盘是否成功。
- 接口相关信息
URI格式:GET /v1/{project_id}/cloudservers/{server_id}/os-volume_attachments
详情请参见查询弹性云服务器挂载磁盘信息。
- 请求示例
GET https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/servers/9f4d9281-95e7-4915-a126-1ee597101e2e/os-volume_attachments
GET https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/cloudservers/9f4d9281-95e7-4915-a126-1ee597101e2e/os-volume_attachments
{endpoint}信息请从地区和终端节点获取。
- 响应示例
{ "volumeAttachments": [ { "device": "/dev/sda", "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", "serverId": "9f4d9281-95e7-4915-a126-1ee597101e2e", "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" }, { "device": "/dev/sdb", "id": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3", "serverId": "9f4d9281-95e7-4915-a126-1ee597101e2e", "volumeId": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3" } ] }
- 接口相关信息