Updated on 2022-09-23 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/{tenant_id}/volumes

        For details, see Creating EVS Disks.

      • Example request

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

        Obtain {endpoint} from the administrator.

        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 /v2.1/{tenant_id}/servers/{server_id}/os-volume_attachments

      For details, see Attaching a Disk to an ECS.

    • Example request

      https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/servers/9f4d9281-95e7-4915-a126-1ee597101e2e/os-volume_attachments

      Obtain {endpoint} from the administrator.

      Body:

      {
          "volumeAttachment": {
              "volumeId": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3",
              "device": "/dev/sdb"
          }
      }
    • Example response
      {
        "volumeAttachment": {
          "id": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3",
          "volumeId": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3",
          "serverId": "9f4d9281-95e7-4915-a126-1ee597101e2e",
          "device": "/dev/sdb"
        }
      }

  3. Verify the disk attachment.

    • API

      URI format: GET /v2.1/{tenant_id}/servers/{server_id}/os-volume_attachments

      For details, see Querying Disks Attached to an ECS.

    • Example request

      https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/servers/9f4d9281-95e7-4915-a126-1ee597101e2e/os-volume_attachments

      Obtain {endpoint} from the administrator.

    • Example response
      {
        "volumeAttachments": [
          {
            "volumeId": "4fc0b4cc-9d6c-431c-be70-3dfeec2ff6e0",
            "id": "4fc0b4cc-9d6c-431c-be70-3dfeec2ff6e0",
            "device": "/dev/sda",
            "serverId": "9f4d9281-95e7-4915-a126-1ee597101e2e"
          },
          {
            "volumeId": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3",
            "id": "51f45e08-1d4f-44c6-a4a9-84a488e0e8d3",
            "device": "/dev/sdb",
            "serverId": "9f4d9281-95e7-4915-a126-1ee597101e2e"
          }
        ]
      }