Help Center/ Bare Metal Server/ API Reference/ Examples/ Example 3: Attaching Disks to a BMS
Updated on 2024-05-17 GMT+08:00

Example 3: Attaching Disks to a BMS

Scenarios

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

Prerequisites

BMSs using certain flavors cannot have EVS disks attached because the servers do not have SDI iNICs or for other reasons. Therefore, perform the following operations to check whether EVS disks can be attached to a BMS:

Call the Querying Flavor Details and Extended Flavor Information API and check the response. If the value of baremetal:__support_evs for the BMS flavor is true, EVS disks can be attached to the BMS. If the value is false or the BMS flavor does not contain this parameter, EVS disks cannot be attached to the BMS.

Procedure

  1. Create an EVS disk.
    • API

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

      For details, see Creating EVS Disks.

    • Example request

      POST https://{EVS Endpoint}/v2/05041fffa40025702f6dc009cc6f8f33/volumes

      Body:

      {
          "volume": {
              "name": "openapi_vol01", 
              "availability_zone": "cn-north-4a", 
              "description": "create for api test", 
              "volume_type": "SSD", 
              "metadata": {
                  "hw:passthrough": "true"
              },
              "size": 40
          }
      }

      BMSs support only SCSI EVS disks. Therefore, the value of hw:passthrough must be true.

    • Example response
      {
          "volume": {
              "attachments": [],
              "links": [
                  {
                      "href": "https://evs.cn-north-4.myhuaweicloud.com/v2/05041fffa40025702f6dc009cc6f8f33/volumes/8ae4ff5b-7e6e-492f-b83a-8a51fdfa3111",
                      "rel": "self"
                  },
                  {
                      "href": "https://evs.cn-north-4.myhuaweicloud.com/05041fffa40025702f6dc009cc6f8f33/volumes/8ae4ff5b-7e6e-492f-b83a-8a51fdfa3111",
                      "rel": "bookmark"
                  }
              ],
              "availability_zone": "cn-north-4a",
              "encrypted": false,
              "updated_at": "2020-11-09T08:19:22.077967",
              "replication_status": "disabled",
              "storage_cluster_id": null,
              "snapshot_id": null,
              "id": "8ae4ff5b-7e6e-492f-b83a-8a51fdfa3111",
              "size": 40,
              "user_id": "0504186e6a8010e01f3ec009a7279baa",
              "metadata": {
                  "hw:passthrough": "true"
              },
              "status": "creating",
              "description": "create for api test",
              "multiattach": false,
              "source_volid": null,
              "consistencygroup_id": null,
              "name": "openapi_vol01",
              "bootable": "false",
              "created_at": "2020-11-09T08:19:22.061273",
              "volume_type": "SSD",
              "shareable": false
          }
      }

      Record the value of id in volume.

  2. Attach the EVS disk to the BMS.
    • API

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

      For details, see Attaching an EVS Disk to a BMS.

    • Example request

      POST https://{BMS Endpoint}/v1/05041fffa40025702f6dc009cc6f8f33/baremetalservers/9ab74d89-61e7-4259-8546-465fdebe4944/attachvolume

      Body:

      {
          "volumeAttachment": {
              "volumeId": "8ae4ff5b-7e6e-492f-b83a-8a51fdfa3111",
              "device": "/dev/sdb"
          }
      }
    • Example response
      {
          "volumeAttachment": {
              "id": "b53f23bd-ee8f-49ec-9420-d1acfeaf91d6",
              "volumeId": "8ae4ff5b-7e6e-492f-b83a-8a51fdfa3111",
              "serverId": "9ab74d89-61e7-4259-8546-465fdebe4944",
              "device": "/dev/sdb"
          }
      }
  3. Check whether the EVS disk is successfully attached to the BMS.
    • API

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

      For details, see Querying EVS Disks Attached to a BMS.

    • Example request

      GET https://{BMS Endpoint}/v1/05041fffa40025702f6dc009cc6f8f33/baremetalservers/9ab74d89-61e7-4259-8546-465fdebe4944/os-volume_attachments

    • Example response
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      {
          "volumeAttachments": [
              {
                  "device": "/dev/sdd",
                  "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
                  "serverId": "9ab74d89-61e7-4259-8546-465fdebe4944",
                  "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803"
              },
              {
                  "device": "/dev/sdb",
                  "id": "b53f23bd-ee8f-49ec-9420-d1acfeaf91d6",
                  "serverId": "9ab74d89-61e7-4259-8546-465fdebe4944",
                  "volumeId": "8ae4ff5b-7e6e-492f-b83a-8a51fdfa3111"
              }
          ]
      }