创建云硬盘
功能介绍
创建按需或包周期云硬盘。
调用方法
请参见如何调用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小时。携带相同幂等标识的多个请求,会认为多个请求为同一个幂等请求,会返回相同的响应体。 约束限制 不涉及。 取值范围 取值为36位的UUID格式字符串,有效期为8小时。 默认取值 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
bssParam |
否 |
BssParamForCreateVolume object |
参数解释 按需和包周期的扩展参数 约束限制 不涉及。 取值范围 不涉及。 默认取值 不涉及。 |
volume |
是 |
CreateVolumeOption object |
参数解释 待创建的云硬盘信息。 约束限制 不涉及。 取值范围 不涉及。 默认取值 不涉及。 |
server_id |
否 |
String |
参数解释 创建云硬盘并挂载到目标虚拟机。 约束限制 创建的云硬盘的计费模式会与虚拟机的计费模式保持一致。 目前只支持ECS服务的虚拟机,暂不支持BMS的裸金属服务器。 取值范围 不涉及。 默认取值 不涉及。 |
OS-SCH-HNT:scheduler_hints |
否 |
CreateVolumeSchedulerHints object |
参数解释 云硬盘调度参数,可用于指定云硬盘创建到某个专属存储池中。 约束限制 不涉及。 取值范围 不涉及。 默认取值 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
chargingMode |
否 |
String |
参数解释 计费模式。 约束限制 不涉及。 取值范围
默认取值 postPaid。 |
isAutoPay |
否 |
String |
参数解释 功能说明:是否立即支付。 约束限制 chargingMode为PrePaid时该参数会生效。 取值范围
默认取值 false。 |
isAutoRenew |
否 |
String |
参数解释 功能说明:是否自动续订。 约束限制 chargingMode为prePaid时该参数会生效。 取值范围
默认取值 false。 |
periodNum |
否 |
Integer |
参数解释 功能说明:订购周期数。 约束限制 chargingMode为prePaid时该参数会生效,并且该参数为为必选。 取值范围
默认取值 不涉及。 |
periodType |
否 |
String |
参数解释 功能说明:订购周期单位。 约束限制 chargingMode为prePaid时该参数会生效,并且该参数为必选。 取值范围
默认取值 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
availability_zone |
是 |
String |
参数解释 指定要创建云硬盘的可用区。 约束限制 不涉及。 取值范围 不涉及。 默认取值 不涉及。 |
backup_id |
否 |
String |
参数解释 备份ID。 可通过云硬盘备份控制台的备份列表页面获取备份ID。 约束限制 从备份创建云硬盘时为必选。 取值范围 不涉及。 默认取值 不涉及。 |
count |
否 |
Integer |
参数解释 批量创云硬盘的个数。 约束限制 如果无该参数,表明只创建1个云硬盘,目前最多支持批量创建100个。 从备份创建云硬盘时,不支持批量创建,数量只能为“1”。 如果发送请求时,将参数值设置为小数,则默认取小数点前的整数。 取值范围 不涉及。 默认取值 不涉及。 |
description |
否 |
String |
参数解释 云硬盘的描述。 约束限制 最大支持85个字符。 取值范围 不涉及。 默认取值 不涉及。 |
enterprise_project_id |
否 |
String |
参数解释 企业项目ID。创建云硬盘时,给云硬盘绑定企业项目ID。 关于企业项目ID的获取及企业项目特性的详细信息,请参考:"企业管理用户指南"。 约束限制 不涉及。 取值范围 不涉及。 默认取值 不涉及。 |
imageRef |
否 |
String |
参数解释 镜像ID,指定该参数表示创建云硬盘方式为从镜像创建云硬盘。 可通过镜像服务控制台的镜像列表页面获取镜像ID。 约束限制 不涉及。 取值范围 不涉及。 默认取值 不涉及。 |
metadata |
否 |
Map<String,String> |
参数解释 云硬盘的metadata信息 ,调用方可以添加或删除metadata信息。当前部分key在EVS服务中有业务场景含义,这部分key的描述如下:
约束限制 不涉及。 取值范围 不涉及。 默认取值 不涉及。 |
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,指定该参数表示创建云硬盘方式为从快照创建云硬盘。 可通过EVS控制台的云硬盘快照列表页面获取云硬盘快照ID。 约束限制 不涉及。 取值范围 不涉及。 默认取值 不涉及。 |
volume_type |
是 |
String |
参数解释 云硬盘类型。 了解不同云硬盘类型的详细信息,请参见 约束限制 当指定的云硬盘类型在availability_zone内不存在时,则创建云硬盘失败。 从快照创建云硬盘时,volume_type字段必须和快照源云硬盘保持一致。 取值范围 目前支持"SATA","SAS","GPSSD","SSD","ESSD","GPSSD2","ESSD2"七种。
默认取值 不涉及。 |
tags |
否 |
Map<String,String> |
参数解释 云硬盘标签信息。 约束限制 不涉及。 取值范围 不涉及。 默认取值 不涉及。 |
iops |
否 |
Integer |
参数解释 给云硬盘配置iops。 约束限制 购买GPSSD2、ESSD2类型的云硬盘时必填,其他类型不能设置。 只支持按需计费。 取值范围 了解GPSSD2、ESSD2类型的iops大小范围,请参见 默认取值 不涉及。 |
throughput |
否 |
Integer |
参数解释 给云硬盘配置吞吐量,单位是MiB/s。 约束限制 购买GPSSD2类型云盘时必填,其他类型不能设置。 只支持按需计费。 取值范围 了解GPSSD2类型的吞吐量大小范围,请参见 默认取值 不涉及。 |
响应参数
状态码:202
参数 |
参数类型 |
描述 |
---|---|---|
job_id |
String |
参数解释 任务ID,云硬盘为按需计费时返回该参数。 如果需要查询job的状态,请参考:"查询job的状态"。 取值范围 不涉及。 |
order_id |
String |
参数解释 订单ID,云硬盘为包周期计费时返回该参数。
取值范围 不涉及。 |
volume_ids |
Array of strings |
参数解释 待创建的云硬盘ID列表。
取值范围 不涉及。 |
状态码:400
参数 |
参数类型 |
描述 |
---|---|---|
code |
String |
参数解释 出现错误时,返回的错误码。 取值范围 错误码和其对应的含义请参考错误码说明。 |
message |
String |
参数解释 出现错误时,返回的错误消息。 取值范围 不涉及。 |
请求示例
-
在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 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()); } } }
-
创建一个共享云硬盘,该云硬盘所在位置为中国-香港可用区一,该云硬盘名称为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 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()); } } }
-
在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
# 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)
-
创建一个共享云硬盘,该云硬盘所在位置为中国-香港可用区一,该云硬盘名称为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
# 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)
-
在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
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) } }
-
创建一个共享云硬盘,该云硬盘所在位置为中国-香港可用区一,该云硬盘名称为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 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) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
202 |
Accepted |
400 |
Bad Request |
错误码
请参见错误码。