Updated on 2024-12-19 GMT+08:00

Attaching a Disk to an ECS

Scenarios

If the existing disks of an ECS fail to meet service requirements, for example, due to insufficient disk space or poor disk performance, you can attach more available disks to the ECS, or call the EVS disk creation API to create disks and attach them to the ECS. To attach an EVS disk to an ECS, you need to call the desired API.

A data disk can be attached by setting the data_volumes parameter during ECS creation or after the ECS is created. This section describes how to attach a disk to a created ECS.

Involved APIs

Attaching a disk involves the following APIs:

Procedure

  1. Create an EVS disk.

    1. Create an EVS disk.
      • API

        URI format: POST /v2/{project_id}/volumes

        For details, see Creating EVS Disks.

      • Example request

        POST https://{endpoint}/v2/74610f3a5ad941998e91f076297ecf27/volumes

        Obtain {endpoint} from Regions and Endpoints.

        Body:

        {
            "volume": {
                "name": "openapi_vol02", 
                "availability_zone":"az_test_01", 
                "description": "create for api test", 
                "volume_type": "SSD", 
                "size": 40
            }
        }
      • Example response
        {
          "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
          }
        }
    2. Record the volume ID in the response.

  2. Attach the disk to the ECS.

    • API

      URI format: POST /v1/{project_id}/cloudservers/{server_id}/attachvolume

      For details, see Attaching a Disk to an ECS.

    • Example request

      POST https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/cloudservers/9f4d9281-95e7-4915-a126-1ee597101e2e/attachvolume

      Obtain {endpoint} from Regions and Endpoints.

      Body:

      {
          "volumeAttachment": {
               "volumeId": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3",
               "device": "/dev/sdb",
               "volume_type": "SSD",
               "count": 5,
               "hw:passthrough": "true"
          },
          "dry_run": false
      }
    • Example response
      {
          "job_id": "ff80808288d41e1b018990260955686a"
      }

  3. Verify the disk attachment.

    • API

      URI format: GET /v1/{project_id}/cloudservers/{server_id}/os-volume_attachments

      For details, see Querying Disk Attachments of an ECS.

    • Example request

      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

      Obtain {endpoint} from Regions and Endpoints.

    • Example response
      {
          "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"
              }
          ]
      }