创建包周期存储库
功能介绍
创建包周期存储库
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/vaults/order
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
vault |
是 |
VaultOrder object |
存储库 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
存储库名称 最小长度:1 最大长度:64 最小长度:1 最大长度:64 |
billing |
是 |
BillingCreate object |
创建参数信息 |
resources |
是 |
Array of ResourceCreate objects |
绑定的备份资源,未在创建时绑定资源填[] 数组长度:0 - 256 |
description |
否 |
String |
描述 最小长度:0 最大长度:255 最小长度:0 最大长度:255 |
backup_policy_id |
否 |
String |
备份策略ID,不设置时为null,不自动备份。 |
tags |
否 |
Array of Tag objects |
标签列表 tags不允许为空列表。 tags中最多包含10个key。 tags中key不允许重复。 数组长度:1 - 10 |
enterprise_project_id |
否 |
String |
企业项目ID,默认为‘0’。 |
auto_bind |
否 |
Boolean |
是否支持自动挂载。 |
bind_rules |
否 |
VaultBindRules object |
自动挂载的规则 |
threshold |
否 |
Integer |
存储库阈值,百分比。 最小值:1 最大值:100 |
smn_notify |
否 |
Boolean |
当容量到达阈值,是否启用通知 |
parameters |
否 |
VaultCreateParameters object |
存储库订单联合参数 |
auto_expand |
否 |
Boolean |
是否开启存储库自动扩容能力(只支持按需存储库)。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
cloud_type |
否 |
String |
公有云:public ;混合云:hybrid |
consistent_level |
是 |
String |
规格,崩溃一致性(crash_consistent)或应用一致性(app_consistent) |
object_type |
是 |
String |
对象类型:云服务器(server),云硬盘(disk),文件系统(turbo),云桌面(workspace),VMware(vmware),关系型数据库(rds),文件(file)。 |
protect_type |
是 |
String |
保护类型:备份(backup)、复制(replication)。 |
size |
是 |
Integer |
容量,单位GB 最小值:10 最大值:10485760 |
charging_mode |
否 |
String |
创建模式,按需:post_paid,包周期:pre_paid,默认为post_paid 缺省值:post_paid |
period_type |
否 |
String |
创建类型,charging_mode为pre_paid必填
|
period_num |
否 |
Integer |
创建类型的数量,charging_mode为pre_paid必填 |
is_auto_renew |
否 |
Boolean |
到期后是否自动续期,默认不续期 缺省值:false |
is_auto_pay |
否 |
Boolean |
是否自动付费,默认为不自动付费 缺省值:false |
console_url |
否 |
String |
跳转URL 最小长度:1 最大长度:255 |
is_multi_az |
否 |
Boolean |
存储库多az属性,默认为false 缺省值:false |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
extra_info |
否 |
ResourceExtraInfo object |
资源附加信息 |
id |
是 |
String |
待备份资源id |
type |
是 |
String |
待备份资源的类型: OS::Nova::Server, OS::Cinder::Volume, OS::Ironic::BareMetalServer, OS::Native::Server, OS::Sfs::Turbo, OS::Workspace::DesktopV2 |
name |
否 |
String |
名称 最小长度:0 最大长度:255 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
exclude_volumes |
否 |
Array of strings |
需要排除备份的卷id。仅在多盘备份特性中有效,排除不需要备份的磁盘。当虚拟机新绑定磁盘时,也能继续排除之前设置不用备份的卷。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
key |
是 |
String |
键。 key最大长度为36个字符。 key不能为空字符串。 key前后空格会被丢弃。 key不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。 key只能由中文,字母,数字,“-”,“_”组成。 |
value |
是 |
String |
值。 添加标签时value值必选,删除标签时value值可选。 value最大长度为43个字符。 value可以为空字符串。 value前后的空格会被丢弃。 value不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。 value只能由中文,字母,数字,“-”,“_”,“.”组成。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
tags |
否 |
Array of BindRulesTags objects |
按tags过滤自动绑定的资源 最小长度:0 最大长度:5 数组长度:0 - 5 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
orders |
Array of CbcOrderResult objects |
订单详情 |
retCode |
Integer |
创建结果代码 0:成功 |
errText |
String |
创建结果信息 |
error_code |
String |
操作错误码 0:无错误 |
参数 |
参数类型 |
描述 |
---|---|---|
cloudServiceId |
String |
云服务ID |
orderId |
String |
订单ID |
subscribeResult |
Integer |
订购结果,1:成功;0:失败 |
resourceId |
String |
包周期资源预生成资源id。 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
请参见错误码。 |
error_msg |
String |
错误信息 |
请求示例
-
创建一个包周期云服务器备份存储库,存储库容量为80G,周期为一个月且绑定一个资源。
POST https://{endpoint}/v3/f841e01fd2b14e7fa41b6ae7aa6b0594/vaults/order { "vault" : { "name" : "vault_name", "billing" : { "consistent_level" : "app_consistent", "object_type" : "server", "protect_type" : "backup", "size" : 80, "charging_mode" : "pre_paid", "period_type" : "month", "period_num" : 1 }, "resources" : [ { "id" : "23a320a5-3efd-4568-b1aa-8dd9183cc64c", "type" : "OS::Nova::Server" } ] } }
-
创建一个包周期云服务器备份存储库,存储库容量阈值为80G,云服务器数量为5,周期为一个月同时绑定一个资源并添加标签。
POST https://{endpoint}/v3/f841e01fd2b14e7fa41b6ae7aa6b0594/vaults/order { "vault" : { "name" : "123", "description" : "description", "backup_policy_id" : "70e9c916-7109-472d-94e7-120900e4ba61", "tags" : [ { "key" : "key", "value" : "value" } ], "auto_bind" : false, "threshold" : 80, "smn_notify" : true, "parameters" : { "combined_order" : { "combined_order_id" : "CS2303030959MR1IT", "combined_order_ecs_num" : 5, "combined_order_num" : 5 } }, "bind_rules" : { "tags" : [ { "key" : "bind_rules_key", "value" : "bind_rules_value" } ] }, "billing" : { "cloud_type" : "public", "is_auto_renew" : false, "is_auto_pay" : false, "console_url" : "https://www.com", "consistent_level" : "app_consistent", "object_type" : "server", "protect_type" : "backup", "size" : 80, "charging_mode" : "pre_paid", "period_type" : "month", "period_num" : 1 }, "resources" : [ { "id" : "8ef08ba1-81f7-4e41-ae49-d3e2fb0ba388", "type" : "OS::Nova::Server", "name" : "server_name", "extra_info" : { "exclude_volumes" : [ "1855eb9a-2b5e-4938-a9f0-aea08b6f9243" ] } } ] } }
响应示例
状态码: 200
OK
{ "orders" : [ { "orderId" : "CS2303030941NJJIW", "cloudServiceId" : "cbr", "subscribeResult" : 1, "resourceId" : "ef3bf6bb-1ffb-46c0-8b23-f935ded5024a" } ], "retCode" : 0, "errText" : "success", "error_code" : 0 }
SDK代码示例
SDK代码示例如下。
Java
-
创建一个包周期云服务器备份存储库,存储库容量为80G,周期为一个月且绑定一个资源。
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.cbr.v1.region.CbrRegion; import com.huaweicloud.sdk.cbr.v1.*; import com.huaweicloud.sdk.cbr.v1.model.*; import java.util.List; import java.util.ArrayList; public class CreatePostPaidVaultSolution { 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); CbrClient client = CbrClient.newBuilder() .withCredential(auth) .withRegion(CbrRegion.valueOf("<YOUR REGION>")) .build(); CreatePostPaidVaultRequest request = new CreatePostPaidVaultRequest(); VaultOrderCreateReqs body = new VaultOrderCreateReqs(); List<ResourceCreate> listVaultResources = new ArrayList<>(); listVaultResources.add( new ResourceCreate() .withId("23a320a5-3efd-4568-b1aa-8dd9183cc64c") .withType("OS::Nova::Server") ); BillingCreate billingVault = new BillingCreate(); billingVault.withConsistentLevel(BillingCreate.ConsistentLevelEnum.fromValue("app_consistent")) .withObjectType(BillingCreate.ObjectTypeEnum.fromValue("server")) .withProtectType(BillingCreate.ProtectTypeEnum.fromValue("backup")) .withSize(80) .withChargingMode(BillingCreate.ChargingModeEnum.fromValue("pre_paid")) .withPeriodType(BillingCreate.PeriodTypeEnum.fromValue("month")) .withPeriodNum(1); VaultOrder vaultbody = new VaultOrder(); vaultbody.withName("vault_name") .withBilling(billingVault) .withResources(listVaultResources); body.withVault(vaultbody); request.withBody(body); try { CreatePostPaidVaultResponse response = client.createPostPaidVault(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()); } } }
-
创建一个包周期云服务器备份存储库,存储库容量阈值为80G,云服务器数量为5,周期为一个月同时绑定一个资源并添加标签。
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
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.cbr.v1.region.CbrRegion; import com.huaweicloud.sdk.cbr.v1.*; import com.huaweicloud.sdk.cbr.v1.model.*; import java.util.List; import java.util.ArrayList; public class CreatePostPaidVaultSolution { 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); CbrClient client = CbrClient.newBuilder() .withCredential(auth) .withRegion(CbrRegion.valueOf("<YOUR REGION>")) .build(); CreatePostPaidVaultRequest request = new CreatePostPaidVaultRequest(); VaultOrderCreateReqs body = new VaultOrderCreateReqs(); CombinedOrder combinedOrderParameters = new CombinedOrder(); combinedOrderParameters.withCombinedOrderId("CS2303030959MR1IT") .withCombinedOrderEcsNum(5) .withCombinedOrderNum(5); VaultCreateParameters parametersVault = new VaultCreateParameters(); parametersVault.withCombinedOrder(combinedOrderParameters); List<BindRulesTags> listBindRulesTags = new ArrayList<>(); listBindRulesTags.add( new BindRulesTags() .withKey("bind_rules_key") .withValue("bind_rules_value") ); VaultBindRules bindRulesVault = new VaultBindRules(); bindRulesVault.withTags(listBindRulesTags); List<Tag> listVaultTags = new ArrayList<>(); listVaultTags.add( new Tag() .withKey("key") .withValue("value") ); List<String> listExtraInfoExcludeVolumes = new ArrayList<>(); listExtraInfoExcludeVolumes.add("1855eb9a-2b5e-4938-a9f0-aea08b6f9243"); ResourceExtraInfo extraInfoResources = new ResourceExtraInfo(); extraInfoResources.withExcludeVolumes(listExtraInfoExcludeVolumes); List<ResourceCreate> listVaultResources = new ArrayList<>(); listVaultResources.add( new ResourceCreate() .withExtraInfo(extraInfoResources) .withId("8ef08ba1-81f7-4e41-ae49-d3e2fb0ba388") .withType("OS::Nova::Server") .withName("server_name") ); BillingCreate billingVault = new BillingCreate(); billingVault.withCloudType(BillingCreate.CloudTypeEnum.fromValue("public")) .withConsistentLevel(BillingCreate.ConsistentLevelEnum.fromValue("app_consistent")) .withObjectType(BillingCreate.ObjectTypeEnum.fromValue("server")) .withProtectType(BillingCreate.ProtectTypeEnum.fromValue("backup")) .withSize(80) .withChargingMode(BillingCreate.ChargingModeEnum.fromValue("pre_paid")) .withPeriodType(BillingCreate.PeriodTypeEnum.fromValue("month")) .withPeriodNum(1) .withIsAutoRenew(false) .withIsAutoPay(false) .withConsoleUrl("https://www.com"); VaultOrder vaultbody = new VaultOrder(); vaultbody.withName("123") .withBilling(billingVault) .withResources(listVaultResources) .withDescription("description") .withBackupPolicyId("70e9c916-7109-472d-94e7-120900e4ba61") .withTags(listVaultTags) .withAutoBind(false) .withBindRules(bindRulesVault) .withThreshold(80) .withSmnNotify(true) .withParameters(parametersVault); body.withVault(vaultbody); request.withBody(body); try { CreatePostPaidVaultResponse response = client.createPostPaidVault(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
-
创建一个包周期云服务器备份存储库,存储库容量为80G,周期为一个月且绑定一个资源。
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
# coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcbr.v1 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 = __import__('os').getenv("CLOUD_SDK_AK") sk = __import__('os').getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = CbrClient.new_builder() \ .with_credentials(credentials) \ .with_region(CbrRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreatePostPaidVaultRequest() listResourcesVault = [ ResourceCreate( id="23a320a5-3efd-4568-b1aa-8dd9183cc64c", type="OS::Nova::Server" ) ] billingVault = BillingCreate( consistent_level="app_consistent", object_type="server", protect_type="backup", size=80, charging_mode="pre_paid", period_type="month", period_num=1 ) vaultbody = VaultOrder( name="vault_name", billing=billingVault, resources=listResourcesVault ) request.body = VaultOrderCreateReqs( vault=vaultbody ) response = client.create_post_paid_vault(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
创建一个包周期云服务器备份存储库,存储库容量阈值为80G,云服务器数量为5,周期为一个月同时绑定一个资源并添加标签。
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
# coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcbr.v1 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 = __import__('os').getenv("CLOUD_SDK_AK") sk = __import__('os').getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = CbrClient.new_builder() \ .with_credentials(credentials) \ .with_region(CbrRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreatePostPaidVaultRequest() combinedOrderParameters = CombinedOrder( combined_order_id="CS2303030959MR1IT", combined_order_ecs_num=5, combined_order_num=5 ) parametersVault = VaultCreateParameters( combined_order=combinedOrderParameters ) listTagsBindRules = [ BindRulesTags( key="bind_rules_key", value="bind_rules_value" ) ] bindRulesVault = VaultBindRules( tags=listTagsBindRules ) listTagsVault = [ Tag( key="key", value="value" ) ] listExcludeVolumesExtraInfo = [ "1855eb9a-2b5e-4938-a9f0-aea08b6f9243" ] extraInfoResources = ResourceExtraInfo( exclude_volumes=listExcludeVolumesExtraInfo ) listResourcesVault = [ ResourceCreate( extra_info=extraInfoResources, id="8ef08ba1-81f7-4e41-ae49-d3e2fb0ba388", type="OS::Nova::Server", name="server_name" ) ] billingVault = BillingCreate( cloud_type="public", consistent_level="app_consistent", object_type="server", protect_type="backup", size=80, charging_mode="pre_paid", period_type="month", period_num=1, is_auto_renew=False, is_auto_pay=False, console_url="https://www.com" ) vaultbody = VaultOrder( name="123", billing=billingVault, resources=listResourcesVault, description="description", backup_policy_id="70e9c916-7109-472d-94e7-120900e4ba61", tags=listTagsVault, auto_bind=False, bind_rules=bindRulesVault, threshold=80, smn_notify=True, parameters=parametersVault ) request.body = VaultOrderCreateReqs( vault=vaultbody ) response = client.create_post_paid_vault(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
-
创建一个包周期云服务器备份存储库,存储库容量为80G,周期为一个月且绑定一个资源。
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cbr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1/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 := cbr.NewCbrClient( cbr.CbrClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreatePostPaidVaultRequest{} var listResourcesVault = []model.ResourceCreate{ { Id: "23a320a5-3efd-4568-b1aa-8dd9183cc64c", Type: "OS::Nova::Server", }, } chargingModeBilling:= model.GetBillingCreateChargingModeEnum().PRE_PAID periodTypeBilling:= model.GetBillingCreatePeriodTypeEnum().MONTH periodNumBilling:= int32(1) billingVault := &model.BillingCreate{ ConsistentLevel: model.GetBillingCreateConsistentLevelEnum().APP_CONSISTENT, ObjectType: model.GetBillingCreateObjectTypeEnum().SERVER, ProtectType: model.GetBillingCreateProtectTypeEnum().BACKUP, Size: int32(80), ChargingMode: &chargingModeBilling, PeriodType: &periodTypeBilling, PeriodNum: &periodNumBilling, } nameVault:= "vault_name" vaultbody := &model.VaultOrder{ Name: &nameVault, Billing: billingVault, Resources: listResourcesVault, } request.Body = &model.VaultOrderCreateReqs{ Vault: vaultbody, } response, err := client.CreatePostPaidVault(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
创建一个包周期云服务器备份存储库,存储库容量阈值为80G,云服务器数量为5,周期为一个月同时绑定一个资源并添加标签。
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cbr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1/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 := cbr.NewCbrClient( cbr.CbrClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreatePostPaidVaultRequest{} combinedOrderIdCombinedOrder:= "CS2303030959MR1IT" combinedOrderEcsNumCombinedOrder:= int32(5) combinedOrderNumCombinedOrder:= int32(5) combinedOrderParameters := &model.CombinedOrder{ CombinedOrderId: &combinedOrderIdCombinedOrder, CombinedOrderEcsNum: &combinedOrderEcsNumCombinedOrder, CombinedOrderNum: &combinedOrderNumCombinedOrder, } parametersVault := &model.VaultCreateParameters{ CombinedOrder: combinedOrderParameters, } var listTagsBindRules = []model.BindRulesTags{ { Key: "bind_rules_key", Value: "bind_rules_value", }, } bindRulesVault := &model.VaultBindRules{ Tags: &listTagsBindRules, } var listTagsVault = []model.Tag{ { Key: "key", Value: "value", }, } var listExcludeVolumesExtraInfo = []string{ "1855eb9a-2b5e-4938-a9f0-aea08b6f9243", } extraInfoResources := &model.ResourceExtraInfo{ ExcludeVolumes: &listExcludeVolumesExtraInfo, } nameResources:= "server_name" var listResourcesVault = []model.ResourceCreate{ { ExtraInfo: extraInfoResources, Id: "8ef08ba1-81f7-4e41-ae49-d3e2fb0ba388", Type: "OS::Nova::Server", Name: &nameResources, }, } cloudTypeBilling:= model.GetBillingCreateCloudTypeEnum().PUBLIC chargingModeBilling:= model.GetBillingCreateChargingModeEnum().PRE_PAID periodTypeBilling:= model.GetBillingCreatePeriodTypeEnum().MONTH periodNumBilling:= int32(1) isAutoRenewBilling:= false isAutoPayBilling:= false consoleUrlBilling:= "https://www.com" billingVault := &model.BillingCreate{ CloudType: &cloudTypeBilling, ConsistentLevel: model.GetBillingCreateConsistentLevelEnum().APP_CONSISTENT, ObjectType: model.GetBillingCreateObjectTypeEnum().SERVER, ProtectType: model.GetBillingCreateProtectTypeEnum().BACKUP, Size: int32(80), ChargingMode: &chargingModeBilling, PeriodType: &periodTypeBilling, PeriodNum: &periodNumBilling, IsAutoRenew: &isAutoRenewBilling, IsAutoPay: &isAutoPayBilling, ConsoleUrl: &consoleUrlBilling, } nameVault:= "123" descriptionVault:= "description" backupPolicyIdVault:= "70e9c916-7109-472d-94e7-120900e4ba61" autoBindVault:= false thresholdVault:= int32(80) smnNotifyVault:= true vaultbody := &model.VaultOrder{ Name: &nameVault, Billing: billingVault, Resources: listResourcesVault, Description: &descriptionVault, BackupPolicyId: &backupPolicyIdVault, Tags: &listTagsVault, AutoBind: &autoBindVault, BindRules: bindRulesVault, Threshold: &thresholdVault, SmnNotify: &smnNotifyVault, Parameters: parametersVault, } request.Body = &model.VaultOrderCreateReqs{ Vault: vaultbody, } response, err := client.CreatePostPaidVault(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
OK |
400 |
Bad Request |
错误码
请参见错误码。