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
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Definition The project ID. For details about how to obtain the project ID, see Obtaining a Project ID. Constraints N/A Range N/A Default Value N/A |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition The user token. You can obtain it by calling the IAM API. The value of X-Subject-Token in the response header is the user token. Constraints N/A Range N/A Default Value N/A |
X-Client-Token |
No |
String |
Definition 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 the same idempotent request and the same response body is returned. Constraints N/A Range The value is a 36-digit character string in the UUID format and is valid for 8 hours. Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
bssParam |
No |
BssParamForCreateVolume object |
Definition The extended parameter of pay-per-use and yearly/monthly billing. Constraints N/A Range N/A Default Value N/A |
volume |
Yes |
CreateVolumeOption object |
Definition The information of the disk to be created. Constraints N/A Range N/A Default Value N/A |
server_id |
No |
String |
Definition The server to attach the disk. Constraints The billing mode of the disk created will be the same as that of the server. Only ECSs are supported currently. BMSs are not supported. Range N/A Default Value N/A |
OS-SCH-HNT:scheduler_hints |
No |
CreateVolumeSchedulerHints object |
Definition The disk scheduling parameter. It can be used to create the disk in a dedicated storage pool. Constraints N/A Range N/A Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
chargingMode |
No |
String |
Definition The billing mode. Constraints N/A Range
Default Value postPaid |
isAutoPay |
No |
String |
Definition Whether to pay immediately. Constraints This parameter is valid only when chargingMode is prePaid. Range
Default Value false |
isAutoRenew |
No |
String |
Definition Whether to automatically renew the subscription. Constraints This parameter is valid only when chargingMode is prePaid. Range
Default Value false |
periodNum |
No |
Integer |
Definition The subscription period. Constraints This parameter is valid and mandatory only when chargingMode is prePaid. Range
Default Value N/A |
periodType |
No |
String |
Definition The unit of the subscription period. Constraints This parameter is valid and mandatory only when chargingMode is prePaid. Range
Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
availability_zone |
Yes |
String |
Definition The AZ where you want to create the disk. Constraints N/A Range N/A Default Value N/A |
backup_id |
No |
String |
Definition The backup ID. You can obtain the backup ID on the backup list page of the disk backup console. Constraints This parameter is mandatory when you create the disk from a backup. Range N/A Default Value N/A |
count |
No |
Integer |
Definition The number of disks to be created in a batch. Constraints You can create up to 100 disks at a time. If this parameter is not specified, only one disk is created. If the disk is created from a backup, batch creation is not supported, and this parameter must be 1. If the specified value is a decimal number, the whole number part will be used by default. Range N/A Default Value N/A |
description |
No |
String |
Definition The disk description. Constraints It can contain a maximum of 85 characters. Range N/A Default Value N/A |
enterprise_project_id |
No |
String |
Definition The enterprise project ID. This ID is bound to the disk during the disk creation. For more information about enterprise projects and how to obtain enterprise project IDs, see Enterprise Management User Guide. Constraints N/A Range N/A Default Value N/A |
imageRef |
No |
String |
Definition The image ID. If this parameter is specified, the disk is created from an image. You can obtain the image ID on the image list page of the IMS console. Constraints N/A Range N/A Default Value N/A |
metadata |
No |
Map<String,String> |
Definition The disk metadata information. Callers can add or remove the metadata information. The keys of this parameter used in EVS are described as follows:
Constraints N/A Range N/A Default Value N/A |
multiattach |
No |
Boolean |
Definition Whether the disk is shareable. Constraints N/A Range The value can be true (shareable) or false (non-shareable). Default Value N/A |
name |
No |
String |
Definition The disk name. If you create one disk, the name value is the disk name, which can contain a maximum of 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. Constraints N/A Range N/A Default Value N/A |
size |
Yes |
Integer |
Definition The disk capacity, in GiB. Constraints
Range N/A Default Value N/A |
snapshot_id |
No |
String |
Definition The snapshot ID. If this parameter is specified, the disk is created from a snapshot. You can obtain it on the snapshot list page of the EVS console. Constraints N/A Range N/A Default Value N/A |
volume_type |
Yes |
String |
Definition The disk type. For details about disk types, see Constraints If the specified disk type is not available in the AZ, the disk will fail to be created. If you create the disk from a snapshot, the volume_type value must be consistent with that of the snapshot's source disk. Range The value can be SATA, SAS, GPSSD, SSD, ESSD, GPSSD2, or ESSD2.
Default Value N/A |
tags |
No |
Map<String,String> |
Definition The disk tag information. Constraints N/A Range N/A Default Value N/A |
iops |
No |
Integer |
Definition The IOPS configured for the disk. Constraints This parameter is mandatory only when you buy a general purpose SSD V2 or extreme SSD V2 disk. Only pay-per-use billing is supported. Range 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. Default Value N/A |
throughput |
No |
Integer |
Definition The throughput configured for a disk. The unit is MiB/s. Constraints This parameter is mandatory only when you buy a general purpose SSD V2 disk. Only pay-per-use billing is supported. Range To learn the throughput range of general purpose SSD V2 disks, see [ [the table of EVS performance data in Disk Types and Performance. Default Value N/A |
Response Parameters
Status code: 202
Parameter |
Type |
Description |
---|---|---|
job_id |
String |
Definition The task ID. This parameter is returned when the disk is billed on a pay-per-use basis. For details about how to query the task status, see Querying Task Status. Range N/A |
order_id |
String |
Definition The order ID. This parameter is returned when the disk is billed on a yearly/monthly basis.
Range N/A |
volume_ids |
Array of strings |
Definition The IDs of the disks to be created.
Range N/A |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error |
Error object |
Definition The error code returned if an error occurs. For the error codes and their meanings, see Error Codes. Range N/A |
Parameter |
Type |
Description |
---|---|---|
code |
String |
Definition The error code returned if an error occurs. Range For the error codes and their meanings, see Error Codes. |
message |
String |
Definition The error message returned if an error occurs. Range N/A |
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 (Create the disk in AZ1 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, capacity to 100 GiB, and subscription period to three months. Add tags to the disk. Enable auto 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.
Java
-
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 67 68
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"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .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 (Create the disk in AZ1 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, capacity to 100 GiB, and subscription period to three months. Add tags to the disk. Enable auto 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 71
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"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .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()); } } }
Python
-
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
# coding: utf-8 import os 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.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) 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 (Create the disk in AZ1 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, capacity to 100 GiB, and subscription period to three months. Add tags to the disk. Enable auto 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
# coding: utf-8 import os 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.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) 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)
Go
-
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
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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). 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 (Create the disk in AZ1 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, capacity to 100 GiB, and subscription period to three months. Add tags to the disk. Enable auto 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 71 72
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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). 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) } }
More
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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot