Updated on 2024-02-27 GMT+08:00

Creating EVS Disks

Function

This API is used to create a pay-per-use or yearly/monthly EVS disk.

Calling Method

For details, see Calling APIs.

URI

POST /v2.1/{project_id}/cloudvolumes

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

The project ID.

For details about how to obtain the project ID, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

The user token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

X-Client-Token

No

String

The idempotence identifier of a request. This parameter value is generated by the client and must be unique among requests. The value is a 36-digit character string in the UUID format and is valid for 8 hours. If multiple requests carry the same idempotent identifier, the requests are considered as an idempotent request and the same response body is returned.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

bssParam

No

BssParamForCreateVolume object

The extended parameter of pay-per-use and yearly/monthly billing.

volume

Yes

CreateVolumeOption object

The information of the disk to be created.

server_id

No

String

The server to attach the disk. The billing mode of the created disk is the same as that of the server. Only ECSs are supported currently. BMSs are not supported.

OS-SCH-HNT:scheduler_hints

No

CreateVolumeSchedulerHints object

The disk scheduling parameter, which can be used to create the disk in a dedicated storage pool.

Table 4 BssParamForCreateVolume

Parameter

Mandatory

Type

Description

chargingMode

No

String

The billing mode. The default value is postPaid. Values:

  • prePaid: yearly/monthly

  • postPaid: pay-per-use

Default: postPaid

Enumeration values:

  • postPaid

  • prePaid

isAutoPay

No

String

Whether to pay immediately. This parameter is valid only when chargingMode is set to prePaid. The default value is false. Values:

  • true: An order is immediately paid from the account balance.

  • false: An order is not paid immediately after being created.

Default: false

Enumeration values:

  • true

  • false

isAutoRenew

No

String

Whether to automatically renew the subscription. This parameter is valid only when chargingMode is set to prePaid. The default value is false. Values:

  • true: automatically renews the subscription. The renewal term is the same as the subscription term.

  • false: does not automatically renew the subscription.

Default: false

Enumeration values:

  • true

  • false

periodNum

No

Integer

The subscription term. This parameter is valid and mandatory only when chargingMode is set to prePaid. Values:

  • If periodType is set to month, the parameter value ranges from 1 to 9.

  • If periodType is set to year, the parameter value is 1.

periodType

No

String

The unit of the subscription term. This parameter is valid and mandatory only when chargingMode is set to prePaid. Values:

  • month

  • year

Enumeration values:

  • month

  • year

cloudServiceConsoleURL

No

String

The URL used to switch to the cloud service console to view information after the subscription is complete.

Table 5 CreateVolumeOption

Parameter

Mandatory

Type

Description

availability_zone

Yes

String

The AZ where you want to create the disk.

backup_id

No

String

The backup ID. This parameter is mandatory when you create the disk from a backup.

count

No

Integer

The number of disks to be created in a batch. If this parameter is not specified, only one disk will be created. You can create a maximum of 100 disks in a batch. If the disk is created from a backup, batch creation is not possible, and this parameter must be set to 1.

If the specified value is a decimal number, the number part will be used by default.

description

No

String

The disk description. You can enter up to 85 characters.

enterprise_project_id

No

String

The enterprise project ID. This ID is associated with the disk during the disk creation.

imageRef

No

String

The image ID. If this parameter is specified, the disk is created from an image.

metadata

No

Map<String,String>

The disk metadata information. The value can be as follows: __system__cmkid:

The encryption CMK ID in metadata. This parameter is used together with __system__encrypted for encryption. The length of cmkid is fixed at 36 bytes.

NOTE:

For details about how to obtain the key ID, see Querying the Key List.

__system__encrypted:

The encryption field in metadata. The value can be 0 (does not encrypt) or 1 (encrypts). If this parameter is not specified, the encryption attribute of the disk is the same as that of the data source. If the disk is not created from a data source, the disk is not encrypted by default.

[full_clone]

If the disk is created from a snapshot and linked cloning needs to be used, set this parameter to 0.

[hw:passthrough]

  • If this parameter value is true, the disk device type is SCSI, which allows ECS OSs to directly access the underlying storage media and supports SCSI reservation commands.

  • If this parameter value is false, the disk device type is VBD, which supports only simple SCSI read/write commands.

  • If this parameter is not specified, the disk device type is VBD.

multiattach

No

Boolean

Whether the disk is shareable. The value can be true (shareable) or false (non-shareable).

name

No

String

The disk name. If you create one disk, the name value is the disk name. You can enter up to 64 characters. If you create multiple disks (the count value greater than 1), the system automatically adds a hyphen followed by a four-digit incremental number, such as -0000, to the end of each disk name. For example, the disk names can be volume-0001 and volume-0002.

size

Yes

Integer

The disk size, in GiB. The restrictions are as follows:

  • System disk: 1 GiB to 1,024 GiB

  • Data disk: 10 GiB to 32,768 GiB

  • This parameter is mandatory when you create an empty disk or use an image or a snapshot to create a disk. If you use an image or a snapshot to create a disk, the disk size cannot be smaller than the image or snapshot size.

  • This parameter is optional if you create the disk from a backup. If not specified, the disk size is the same as the backup size.

snapshot_id

No

String

The snapshot ID. If this parameter is specified, the disk is created from a snapshot.

volume_type

Yes

String

The disk type.

The value can be SATA, SAS, GPSSD, SSD, ESSD, GPSSD2, or ESSD2.

  • SATA: the common I/O type (sold out)

  • SAS: the high I/O type

  • GPSSD: the general purpose SSD type

  • SSD: the ultra-high I/O type

  • ESSD: the extreme SSD type

  • GPSSD2: the general purpose SSD V2 type

  • ESSD2: the extreme SSD V2 type

If the specified disk type is not available in the AZ, the disk will fail to be created.

NOTE:

When you create a disk from a snapshot, ensure that the disk type of the new disk is consistent with that of the snapshot's source disk. For details about disk types, see

Disk Types and Performance.

Enumeration values:

  • SATA

  • SAS

  • GPSSD

  • SSD

  • ESSD

  • GPSSD2

  • ESSD2

tags

No

Map<String,String>

The disk tag information.

sys_tags

No

Map<String,String>

The disk system tag information.

iops

No

Integer

The configured IOPS. This parameter is mandatory only when a general purpose SSD V2 or an extreme SSD V2 disk is created.

NOTE:

To learn the IOPS ranges of the general purpose SSD V2 and extreme SSD V2 disks, see [ [the table of EVS performance data in Disk Types and Performance.

  • Only pay-per-use billing is supported.

throughput

No

Integer

The configured throughput, in the unit of MiB/s. This parameter is mandatory only when a general purpose SSD V2 disk is created.

NOTE:

To learn the throughput range of the general purpose SSD V2 disks, see [ [the table of EVS performance data in Disk Types and Performance.

  • Only pay-per-use billing is supported.

Table 6 CreateVolumeSchedulerHints

Parameter

Mandatory

Type

Description

dedicated_storage_id

No

String

The dedicated storage pool ID. If this parameter is specified, the disks will be created in the specified storage pool.

Response Parameters

Status code: 202

Table 7 Response body parameters

Parameter

Type

Description

job_id

String

The task ID. This parameter is returned when the disk is billed on a pay-per-use basis.

order_id

String

The order ID. This parameter is returned when the disk is billed on a yearly/monthly basis.

  • If you add a disk to a yearly/monthly server, the system automatically attaches the disk to the server. In this case, this parameter is also returned.

  • If you need to pay for the order, see Paying Yearly/Monthly Product Orders.

volume_ids

Array of strings

The IDs of the disks to be created.

  • If 404 is returned when you query the details of a disk by disk ID, the disk is being created or has failed to be created.

  • You can query whether the disk creation task is complete by task ID. For details, see Querying Task Status.

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

error

Error object

The error message returned if an error occurs. For details, seeParameters in the error field.

Table 9 Error

Parameter

Type

Description

code

String

The error code returned if an error occurs. For the error codes and their meanings, see Error Codes.

message

String

The error message returned if an error occurs.

Example Requests

  • Creating a shared, encrypted EVS disk in storage pool 1b6198f2-20a6-5dcc-aa21-58c1af5dc488 (Deploy the disk in AZ 1 of CN-Hong Kong. Set the disk name to EVS-Test, device type to SCSI, disk type to high I/O, and size to 10 GiB.)

    POST https://{endpoint}/v2.1/{project_id}/cloudvolumes
    
    {
      "volume" : {
        "availability_zone" : "ap-southeast-1a",
        "size" : 10,
        "name" : "EVS-Test",
        "volume_type" : "SAS",
        "metadata" : {
          "hw:passthrough" : "true",
          "__system__encrypted" : "1",
          "__system__cmkid" : "94257794-d7aa-462c-9eaa-9f32c05b9966",
          "region" : "ap-southeast-1"
        },
        "multiattach" : true,
        "enterprise_project_id" : "0"
      },
      "OS-SCH-HNT:scheduler_hints" : {
        "dedicated_storage_id" : "1b6198f2-20a6-5dcc-aa21-58c1af5dc488"
      }
    }
  • Creating a shared EVS disk (Deploy the disk in AZ 1 of the CN-Hong Kong region. Set the disk name to EVS-Test2, type to general purpose SSD V2, IOPS to 5,000, throughput to 500 MiB/s, size to 100 GiB, and subscription period to three months. Add tags to the disk. Enable automatic subscription renewal. You will be billed for the disk immediately after the order is placed.)

    POST https://{endpoint}/v2.1/{project_id}/cloudvolumes
    
    {
      "volume": {
        "count": 1,
        "availability_zone": "ap-southeast-1",
        "size": 100,
        "name": "EVS-Test2",
        "volume_type": "GPSSD2",
        "metadata": {},
        "tags": {
          "key_string": "value_string"
        },
        "iops": 5000,
        "throughput": 500,
        "multiattach": 1
      },
      "bssParam": {
        "chargingMode": "prePaid",
        "periodType": "month",
        "periodNum": 3,
        "isAutoPay": true,
        "isAutoRenew": true,
      }
    }

Example Responses

Status code: 202

Accepted

{
  "job_id" : "70a599e0-31e7-49b7-b260-868f441e862b",
  "volume_ids" : [ "e1fa3e72-8c92-4871-9152-bf66fef0afe9" ]
}

Status code: 400

Bad Request

{
  "error" : {
    "message" : "XXXX",
    "code" : "XXX"
  }
}

SDK Sample Code

The SDK sample code is as follows.

  • Creating a shared, encrypted EVS disk in storage pool 1b6198f2-20a6-5dcc-aa21-58c1af5dc488 (Deploy the disk in AZ 1 of CN-Hong Kong. Set the disk name to EVS-Test, device type to SCSI, disk type to high I/O, and size to 10 GiB.)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.evs.v2.region.EvsRegion;
    import com.huaweicloud.sdk.evs.v2.*;
    import com.huaweicloud.sdk.evs.v2.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateVolumeSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            EvsClient client = EvsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(EvsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateVolumeRequest request = new CreateVolumeRequest();
            CreateVolumeRequestBody body = new CreateVolumeRequestBody();
            CreateVolumeSchedulerHints osschhntschedulerhintsbody = new CreateVolumeSchedulerHints();
            osschhntschedulerhintsbody.withDedicatedStorageId("1b6198f2-20a6-5dcc-aa21-58c1af5dc488");
            Map<String, String> listVolumeMetadata = new HashMap<>();
            listVolumeMetadata.put("hw:passthrough", "true");
            listVolumeMetadata.put("__system__encrypted", "1");
            listVolumeMetadata.put("__system__cmkid", "94257794-d7aa-462c-9eaa-9f32c05b9966");
            listVolumeMetadata.put("region", "ap-southeast-1");
            CreateVolumeOption volumebody = new CreateVolumeOption();
            volumebody.withAvailabilityZone("ap-southeast-1a")
                .withEnterpriseProjectId("0")
                .withMetadata(listVolumeMetadata)
                .withMultiattach(true)
                .withName("EVS-Test")
                .withSize(10)
                .withVolumeType(CreateVolumeOption.VolumeTypeEnum.fromValue("SAS"));
            body.withOsSCHHNTSchedulerHints(osschhntschedulerhintsbody);
            body.withVolume(volumebody);
            request.withBody(body);
            try {
                CreateVolumeResponse response = client.createVolume(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • Creating a shared EVS disk (Deploy the disk in AZ 1 of the CN-Hong Kong region. Set the disk name to EVS-Test2, type to general purpose SSD V2, IOPS to 5,000, throughput to 500 MiB/s, size to 100 GiB, and subscription period to three months. Add tags to the disk. Enable automatic subscription renewal. You will be billed for the disk immediately after the order is placed.)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.evs.v2.region.EvsRegion;
    import com.huaweicloud.sdk.evs.v2.*;
    import com.huaweicloud.sdk.evs.v2.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateVolumeSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            EvsClient client = EvsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(EvsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateVolumeRequest request = new CreateVolumeRequest();
            CreateVolumeRequestBody body = new CreateVolumeRequestBody();
            Map<String, String> listVolumeTags = new HashMap<>();
            listVolumeTags.put("key_string", "value_string");
            CreateVolumeOption volumebody = new CreateVolumeOption();
            volumebody.withAvailabilityZone("ap-southeast-1")
                .withCount(1)
                .withMultiattach(1)
                .withName("EVS-Test2")
                .withSize(100)
                .withVolumeType(CreateVolumeOption.VolumeTypeEnum.fromValue("GPSSD2"))
                .withTags(listVolumeTags)
                .withIops(5000)
                .withThroughput(500);
            BssParamForCreateVolume bssParambody = new BssParamForCreateVolume();
            bssParambody.withChargingMode(BssParamForCreateVolume.ChargingModeEnum.fromValue("prePaid"))
                .withIsAutoPay(BssParamForCreateVolume.IsAutoPayEnum.fromValue("true"))
                .withIsAutoRenew(BssParamForCreateVolume.IsAutoRenewEnum.fromValue("true"))
                .withPeriodNum(3)
                .withPeriodType(BssParamForCreateVolume.PeriodTypeEnum.fromValue("month"));
            body.withVolume(volumebody);
            body.withBssParam(bssParambody);
            request.withBody(body);
            try {
                CreateVolumeResponse response = client.createVolume(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • Creating a shared, encrypted EVS disk in storage pool 1b6198f2-20a6-5dcc-aa21-58c1af5dc488 (Deploy the disk in AZ 1 of CN-Hong Kong. Set the disk name to EVS-Test, device type to SCSI, disk type to high I/O, and size to 10 GiB.)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    # coding: utf-8
    
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkevs.v2.region.evs_region import EvsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkevs.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.getenv("CLOUD_SDK_AK")
        sk = os.getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = EvsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(EvsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateVolumeRequest()
            osschhntschedulerhintsbody = CreateVolumeSchedulerHints(
                dedicated_storage_id="1b6198f2-20a6-5dcc-aa21-58c1af5dc488"
            )
            listMetadataVolume = {
                "hw:passthrough": "true",
                "__system__encrypted": "1",
                "__system__cmkid": "94257794-d7aa-462c-9eaa-9f32c05b9966",
                "region": "ap-southeast-1"
            }
            volumebody = CreateVolumeOption(
                availability_zone="ap-southeast-1a",
                enterprise_project_id="0",
                metadata=listMetadataVolume,
                multiattach=True,
                name="EVS-Test",
                size=10,
                volume_type="SAS"
            )
            request.body = CreateVolumeRequestBody(
                os_sch_hn_tscheduler_hints=osschhntschedulerhintsbody,
                volume=volumebody
            )
            response = client.create_volume(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Creating a shared EVS disk (Deploy the disk in AZ 1 of the CN-Hong Kong region. Set the disk name to EVS-Test2, type to general purpose SSD V2, IOPS to 5,000, throughput to 500 MiB/s, size to 100 GiB, and subscription period to three months. Add tags to the disk. Enable automatic subscription renewal. You will be billed for the disk immediately after the order is placed.)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    # coding: utf-8
    
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkevs.v2.region.evs_region import EvsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkevs.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.getenv("CLOUD_SDK_AK")
        sk = os.getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = EvsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(EvsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateVolumeRequest()
            listTagsVolume = {
                "key_string": "value_string"
            }
            volumebody = CreateVolumeOption(
                availability_zone="ap-southeast-1",
                count=1,
                multiattach=1,
                name="EVS-Test2",
                size=100,
                volume_type="GPSSD2",
                tags=listTagsVolume,
                iops=5000,
                throughput=500
            )
            bssParambody = BssParamForCreateVolume(
                charging_mode="prePaid",
                is_auto_pay="true",
                is_auto_renew="true",
                period_num=3,
                period_type="month"
            )
            request.body = CreateVolumeRequestBody(
                volume=volumebody,
                bss_param=bssParambody
            )
            response = client.create_volume(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Creating a shared, encrypted EVS disk in storage pool 1b6198f2-20a6-5dcc-aa21-58c1af5dc488 (Deploy the disk in AZ 1 of CN-Hong Kong. Set the disk name to EVS-Test, device type to SCSI, disk type to high I/O, and size to 10 GiB.)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        evs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/evs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/evs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/evs/v2/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := evs.NewEvsClient(
            evs.EvsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateVolumeRequest{}
    	dedicatedStorageIdOSSCHHNTschedulerHints:= "1b6198f2-20a6-5dcc-aa21-58c1af5dc488"
    	osschhntschedulerhintsbody := &model.CreateVolumeSchedulerHints{
    		DedicatedStorageId: &dedicatedStorageIdOSSCHHNTschedulerHints,
    	}
    	var listMetadataVolume = map[string]string{
            "hw:passthrough": "true",
            "__system__encrypted": "1",
            "__system__cmkid": "94257794-d7aa-462c-9eaa-9f32c05b9966",
            "region": "ap-southeast-1",
        }
    	enterpriseProjectIdVolume:= "0"
    	multiattachVolume:= true
    	nameVolume:= "EVS-Test"
    	volumebody := &model.CreateVolumeOption{
    		AvailabilityZone: "ap-southeast-1a",
    		EnterpriseProjectId: &enterpriseProjectIdVolume,
    		Metadata: listMetadataVolume,
    		Multiattach: &multiattachVolume,
    		Name: &nameVolume,
    		Size: int32(10),
    		VolumeType: model.GetCreateVolumeOptionVolumeTypeEnum().SAS,
    	}
    	request.Body = &model.CreateVolumeRequestBody{
    		OSSCHHNTschedulerHints: osschhntschedulerhintsbody,
    		Volume: volumebody,
    	}
    	response, err := client.CreateVolume(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • Creating a shared EVS disk (Deploy the disk in AZ 1 of the CN-Hong Kong region. Set the disk name to EVS-Test2, type to general purpose SSD V2, IOPS to 5,000, throughput to 500 MiB/s, size to 100 GiB, and subscription period to three months. Add tags to the disk. Enable automatic subscription renewal. You will be billed for the disk immediately after the order is placed.)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        evs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/evs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/evs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/evs/v2/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := evs.NewEvsClient(
            evs.EvsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateVolumeRequest{}
    	var listTagsVolume = map[string]string{
            "key_string": "value_string",
        }
    	countVolume:= int32(1)
    	multiattachVolume:= 1
    	nameVolume:= "EVS-Test2"
    	iopsVolume:= int32(5000)
    	throughputVolume:= int32(500)
    	volumebody := &model.CreateVolumeOption{
    		AvailabilityZone: "ap-southeast-1",
    		Count: &countVolume,
    		Multiattach: &multiattachVolume,
    		Name: &nameVolume,
    		Size: int32(100),
    		VolumeType: model.GetCreateVolumeOptionVolumeTypeEnum().GPSSD2,
    		Tags: listTagsVolume,
    		Iops: &iopsVolume,
    		Throughput: &throughputVolume,
    	}
    	chargingModeBssParam:= model.GetBssParamForCreateVolumeChargingModeEnum().PRE_PAID
    	isAutoPayBssParam:= model.GetBssParamForCreateVolumeIsAutoPayEnum().TRUE
    	isAutoRenewBssParam:= model.GetBssParamForCreateVolumeIsAutoRenewEnum().TRUE
    	periodNumBssParam:= int32(3)
    	periodTypeBssParam:= model.GetBssParamForCreateVolumePeriodTypeEnum().MONTH
    	bssParambody := &model.BssParamForCreateVolume{
    		ChargingMode: &chargingModeBssParam,
    		IsAutoPay: &isAutoPayBssParam,
    		IsAutoRenew: &isAutoRenewBssParam,
    		PeriodNum: &periodNumBssParam,
    		PeriodType: &periodTypeBssParam,
    	}
    	request.Body = &model.CreateVolumeRequestBody{
    		Volume: volumebody,
    		BssParam: bssParambody,
    	}
    	response, err := client.CreateVolume(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

202

Accepted

400

Bad Request

Error Codes

See Error Codes.