创建云硬盘
功能介绍
创建按需或包周期云硬盘。
调用方法
请参见如何调用API。
URI
POST /v2.1/{project_id}/cloudvolumes
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID。 获取方法请参见"获取项目ID"。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
X-Client-Token |
否 |
String |
请求的幂等标识。该参数的值由客户端生成,需要确保不同请求的参数值唯一,取值为36位的UUID格式字符串,有效期为8小时。携带相同幂等标识的多个请求,会认为多个请求为同一个幂等请求,会返回相同的响应体。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
bssParam |
否 |
BssParamForCreateVolume object |
按需和包周期的扩展参数 |
volume |
是 |
CreateVolumeOption object |
待创建的云硬盘信息 |
server_id |
否 |
String |
创建云硬盘并挂载到目标虚拟机。 创建的云硬盘的计费模式会与虚拟机的计费模式保持一致。 目前只支持ECS服务的虚拟机,暂不支持BMS的裸金属服务器。 |
OS-SCH-HNT:scheduler_hints |
否 |
CreateVolumeSchedulerHints object |
云硬盘调度参数,可用于指定云硬盘创建到某个专属存储池中 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
chargingMode |
否 |
String |
功能说明:计费模式。默认值为postPaid。 取值范围:
缺省值:postPaid 枚举值:
|
isAutoPay |
否 |
String |
功能说明:是否立即支付。chargingMode为PrePaid时该参数会生效。默认值为false。 取值范围:
缺省值:false 枚举值:
|
isAutoRenew |
否 |
String |
功能说明:是否自动续订。chargingMode为prePaid时该参数会生效。默认值为false。 取值范围:
缺省值:false 枚举值:
|
periodNum |
否 |
Integer |
功能说明:订购周期数,chargingMode为prePaid时该参数会生效,并且该参数为为必选。 取值范围:
|
periodType |
否 |
String |
功能说明:订购周期单位。chargingMode为prePaid时该参数会生效,并且该参数为必选。 取值范围:
枚举值:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
availability_zone |
是 |
String |
指定要创建云硬盘的可用区。 |
backup_id |
否 |
String |
备份ID,从备份创建云硬盘时为必选。 |
count |
否 |
Integer |
批量创云硬盘的个数。如果无该参数,表明只创建1个云硬盘,目前最多支持批量创建100个。 从备份创建云硬盘时,不支持批量创建,数量只能为“1”。 如果发送请求时,将参数值设置为小数,则默认取小数点前的整数。 |
description |
否 |
String |
云硬盘的描述。最大支持85个字符。 |
enterprise_project_id |
否 |
String |
企业项目ID。创建云硬盘时,给云硬盘绑定企业项目ID。 |
imageRef |
否 |
String |
镜像ID,指定该参数表示创建云硬盘方式为从镜像创建云硬盘。 |
metadata |
否 |
Map<String,String> |
创建云硬盘的metadata信息 可选参数如下:[__system__cmkid] metadata中的加密cmkid字段,与__system__encrypted配合表示需要加密,cmkid长度固定为36个字节。
说明:
请求获取密钥ID的方法请参考:"查询密钥列表"。 [__system__encrypted] metadata中的表示加密功能的字段,0代表不加密,1代表加密。不指定该字段时,云硬盘的加密属性与数据源保持一致,如果不是从数据源创建的场景,则默认不加密。 [full_clone] 从快照创建云硬盘时,如需使用link克隆方式,请指定该字段的值为0。 [hw:passthrough]
|
multiattach |
否 |
Boolean |
是否为共享云硬盘。true为共享盘,false为普通云硬盘。 |
name |
否 |
String |
云硬盘名称。如果为创建单个云硬盘,name为云硬盘名称。最大支持64个字符。创建的云硬盘数量(count字段对应的值)大于1时,为区分不同云硬盘,创建过程中系统会自动在名称后加“-0000”的类似标记。例如:volume-0001、volume-0002。 |
size |
是 |
Integer |
云硬盘大小,单位为GiB,其限制如下: -系统盘:1GiB-1024GiB -数据盘:10GiB-32768GiB -创建空白云硬盘和从 镜像/快照 创建云硬盘时,size为必选,且云硬盘大小不能小于 镜像/快照 大小。 -从备份创建云硬盘时,size为可选,不指定size时,云硬盘大小和备份大小一致。 |
snapshot_id |
否 |
String |
快照ID,指定该参数表示创建云硬盘方式为从快照创建云硬盘。 |
volume_type |
是 |
String |
云硬盘类型。 目前支持"SATA","SAS","GPSSD","SSD","ESSD","GPSSD2","ESSD2"七种。
当指定的云硬盘类型在availability_zone内不存在时,则创建云硬盘失败。
说明:
从快照创建云硬盘时,volume_type字段必须和快照源云硬盘保持一致。 了解不同云硬盘类型的详细信息,请参见 云硬盘类型及性能介绍。 枚举值:
|
tags |
否 |
Map<String,String> |
云硬盘标签信息。 |
iops |
否 |
Integer |
给云硬盘配置iops,购买GPSSD2、ESSD2类型的云硬盘时必填,其他类型不能设置。
说明:
了解GPSSD2、ESSD2类型的iops大小范围,请参见
|
throughput |
否 |
Integer |
给云硬盘配置吞吐量,单位是MiB/s,购买GPSSD2类型云盘时必填,其他类型不能设置。
说明:
了解GPSSD2类型的吞吐量大小范围,请参见
|
响应参数
状态码: 202
参数 |
参数类型 |
描述 |
---|---|---|
job_id |
String |
任务ID,云硬盘为按需计费时返回该参数。
|
order_id |
String |
订单ID,云硬盘为包周期计费时返回该参数。
|
volume_ids |
Array of strings |
待创建的云硬盘ID列表。
|
状态码: 400
请求示例
- 在DSS存储池1b6198f2-20a6-5dcc-aa21-58c1af5dc488中创建一个共享加密云硬盘,该云硬盘所在的位置为中国-香港可用区一,该云硬盘的名称为EVS-Test,云硬盘模式为SCSI,云硬盘类型为高IO,容量为10GiB。
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" } }
- 创建一个共享云硬盘,该云硬盘所在位置为中国-香港可用区一,该云硬盘名称为EVS-Test2,云硬盘类型为通用型SSD V2,IOPS性能配置为5000,吞吐量性能配置为500MiB/s,容量为100GiB,并为该云硬盘添加标签。该云硬盘订购周期为3个月,且开通自动续订,下单后立即从帐户余额中自动扣费。
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, } }
响应示例
状态码: 202
Accepted
{ "job_id" : "70a599e0-31e7-49b7-b260-868f441e862b", "volume_ids" : [ "e1fa3e72-8c92-4871-9152-bf66fef0afe9" ] }
状态码: 400
Bad Request
{ "error" : { "message" : "XXXX", "code" : "XXX" } }
SDK代码示例
SDK代码示例如下。
- 在DSS存储池1b6198f2-20a6-5dcc-aa21-58c1af5dc488中创建一个共享加密云硬盘,该云硬盘所在的位置为中国-香港可用区一,该云硬盘的名称为EVS-Test,云硬盘模式为SCSI,云硬盘类型为高IO,容量为10GiB。
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()); } } }
- 创建一个共享云硬盘,该云硬盘所在位置为中国-香港可用区一,该云硬盘名称为EVS-Test2,云硬盘类型为通用型SSD V2,IOPS性能配置为5000,吞吐量性能配置为500MiB/s,容量为100GiB,并为该云硬盘添加标签。该云硬盘订购周期为3个月,且开通自动续订,下单后立即从帐户余额中自动扣费。
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()); } } }
- 在DSS存储池1b6198f2-20a6-5dcc-aa21-58c1af5dc488中创建一个共享加密云硬盘,该云硬盘所在的位置为中国-香港可用区一,该云硬盘的名称为EVS-Test,云硬盘模式为SCSI,云硬盘类型为高IO,容量为10GiB。
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)
- 创建一个共享云硬盘,该云硬盘所在位置为中国-香港可用区一,该云硬盘名称为EVS-Test2,云硬盘类型为通用型SSD V2,IOPS性能配置为5000,吞吐量性能配置为500MiB/s,容量为100GiB,并为该云硬盘添加标签。该云硬盘订购周期为3个月,且开通自动续订,下单后立即从帐户余额中自动扣费。
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)
- 在DSS存储池1b6198f2-20a6-5dcc-aa21-58c1af5dc488中创建一个共享加密云硬盘,该云硬盘所在的位置为中国-香港可用区一,该云硬盘的名称为EVS-Test,云硬盘模式为SCSI,云硬盘类型为高IO,容量为10GiB。
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) } }
- 创建一个共享云硬盘,该云硬盘所在位置为中国-香港可用区一,该云硬盘名称为EVS-Test2,云硬盘类型为通用型SSD V2,IOPS性能配置为5000,吞吐量性能配置为500MiB/s,容量为100GiB,并为该云硬盘添加标签。该云硬盘订购周期为3个月,且开通自动续订,下单后立即从帐户余额中自动扣费。
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) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
202 |
Accepted |
400 |
Bad Request |
错误码
请参见错误码。