更新时间:2024-03-12 GMT+08:00
分享

创建存储库

功能介绍

创建存储库

调用方法

请参见如何调用API

URI

POST /v3/{project_id}/vaults

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

表3 请求Body参数

参数

是否必选

参数类型

描述

vault

VaultCreate object

存储库创建参数

表4 VaultCreate

参数

是否必选

参数类型

描述

backup_policy_id

String

备份策略ID,不设置时为null,不自动备份。

billing

BillingCreate object

创建参数信息

description

String

描述

最小长度:0

最大长度:64

name

String

存储库名称

最小长度:1

最大长度:64

resources

Array of ResourceCreate objects

绑定的备份资源,未在创建时绑定资源填[]

数组长度:0 - 255

tags

Array of Tag objects

标签列表 tags不允许为空列表。 tags中最多包含10个key。 tags中key不允许重复。

enterprise_project_id

String

企业项目ID,默认为‘0’。

auto_bind

Boolean

是否支持自动挂载。

bind_rules

VaultBindRules object

自动挂载的规则

auto_expand

Boolean

是否开启存储库自动扩容能力(只支持按需存储库)。

threshold

Integer

存储库容量阈值,已用容量占总容量达到此百分比,将根据 smn_notify 参数设置选择是否发送相关通知。 默认值为:80 最大值:100 最小值:1

最小值:1

最大值:100

缺省值:80

smn_notify

Boolean

存储库smn消息通知开关。 默认值为 true。

缺省值:true

backup_name_prefix

String

备份名称前缀,设置后该存储库自动备份产生的备份副本都将携带该备份名称前缀

最小长度:0

最大长度:32

demand_billing

Boolean

存储库使用是否允许超出容量,只有创建包周期存储库时才允许该值为 true

缺省值:false

sys_lock_source_service

String

用于标识SMB服务,您可以设置为SMB或者空

表5 BillingCreate

参数

是否必选

参数类型

描述

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必填

  • year: 按年

  • month: 按月

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

表6 ResourceCreate

参数

是否必选

参数类型

描述

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

表7 ResourceExtraInfo

参数

是否必选

参数类型

描述

exclude_volumes

Array of strings

需要排除备份的卷id。仅在多盘备份特性中有效,排除不需要备份的磁盘。当虚拟机新绑定磁盘时,也能继续排除之前设置不用备份的卷。

表8 Tag

参数

是否必选

参数类型

描述

key

String

键。

key最大长度为36个字符。

key不能为空字符串。

key前后空格会被丢弃。

key不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。

key只能由中文,字母,数字,“-”,“_”组成。

value

String

值。

添加标签时value值必选,删除标签时value值可选。

value最大长度为43个字符。

value可以为空字符串。

value前后的空格会被丢弃。

value不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。

value只能由中文,字母,数字,“-”,“_”,“.”组成。

表9 VaultBindRules

参数

是否必选

参数类型

描述

tags

Array of BindRulesTags objects

按tags过滤自动绑定的资源

最小长度:0

最大长度:5

数组长度:0 - 5

表10 BindRulesTags

参数

是否必选

参数类型

描述

key

String

key不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。

key只能由中文,字母,数字,“-”,“_”组成。

value

String

value不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。

value只能由中文,字母,数字,“-”,“_”,“.”组成。

响应参数

状态码: 200

表11 响应Body参数

参数

参数类型

描述

vault

VaultCreateResource object

存储库查询返回对象

表12 VaultCreateResource

参数

参数类型

描述

billing

Billing object

运营信息

description

String

存储库自定义描述信息。

最小长度:0

最大长度:255

id

String

存储库ID

name

String

存储库名称

最小长度:1

最大长度:64

project_id

String

项目ID

provider_id

String

存储库资源类型id

resources

Array of ResourceResp objects

存储库资源

tags

Array of Tag objects

存储库标签

enterprise_project_id

String

企业项目id,默认为‘0’。

auto_bind

Boolean

是否自动绑定,默认为false,不支持。

bind_rules

VaultBindRules object

绑定规则

user_id

String

用户id

created_at

String

创建时间,例如:"2020-02-05T10:38:34.209782"

auto_expand

Boolean

是否开启存储库自动扩容能力(只支持按需存储库)。

smn_notify

Boolean

存储库smn消息通知开关

缺省值:true

threshold

Integer

存储库容量阈值,已用容量占总容量达到此百分比即发送相关通知

最小值:1

最大值:100

缺省值:80

errText

String

包周期创建错误信息

retCode

String

包周期订购结果

orders

Array of CbcOrderResult objects

包周期创建订单信息

backup_name_prefix

String

备份名称前缀

最小长度:0

最大长度:32

demand_billing

Boolean

是否允许使用超出存储库容量

缺省值:false

cbc_delete_count

Integer

存储库删除次数

缺省值:0

frozen

Boolean

存储库是否冻结

缺省值:false

表13 Billing

参数

参数类型

描述

allocated

Integer

已分配容量,单位GB

charging_mode

String

创建模式,按需:post_paid,包周期:pre_paid,默认为post_paid

cloud_type

String

公有云:public ;混合云:hybrid

consistent_level

String

规格,崩溃一致性(crash_consistent)或应用一致性(app_consistent)

object_type

String

对象类型:云服务器(server),云硬盘(disk),文件系统(turbo),云桌面(workspace),VMware(vmware),关系型数据库(rds),文件(file)。

order_id

String

订单ID

product_id

String

产品ID

protect_type

String

保护类型:备份(backup)、复制(replication)。

size

Integer

容量,单位GB

最小值:1

最大值:10485760

spec_code

String

规格编码。 云服务备份存储库:vault.backup.server.normal;云硬盘备份存储库:vault.backup.volume.normal;文件备份存储库:vault.backup.turbo.normal

status

String

存储库状态

  • available: 可用

  • lock: 锁定

  • frozen: 冻结

  • deleting: 删除中

  • error: 异常

storage_unit

String

存储库桶名

used

Integer

已使用容量,单位MB

frozen_scene

String

冻结场景

is_multi_az

Boolean

存储库多az属性

缺省值:false

表14 ResourceResp

参数

参数类型

描述

extra_info

ResourceExtraInfo object

资源附加信息

id

String

待备份资源id

name

String

待备份资源名称

最小长度:0

最大长度:255

protect_status

String

保护状态

  • available: 可用

  • error: 异常

  • protecting: 保护中

  • restoring: 恢复中

  • removing: 删除中

size

Integer

资源已分配容量,单位为GB

type

String

待备份资源的类型: OS::Nova::Server, OS::Cinder::Volume, OS::Ironic::BareMetalServer, OS::Native::Server, OS::Sfs::Turbo, OS::Workspace::DesktopV2

backup_size

Integer

副本大小

backup_count

Integer

副本数量

表15 ResourceExtraInfo

参数

参数类型

描述

exclude_volumes

Array of strings

需要排除备份的卷id。仅在多盘备份特性中有效,排除不需要备份的磁盘。当虚拟机新绑定磁盘时,也能继续排除之前设置不用备份的卷。

表16 Tag

参数

参数类型

描述

key

String

键。

key最大长度为36个字符。

key不能为空字符串。

key前后空格会被丢弃。

key不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。

key只能由中文,字母,数字,“-”,“_”组成。

value

String

值。

添加标签时value值必选,删除标签时value值可选。

value最大长度为43个字符。

value可以为空字符串。

value前后的空格会被丢弃。

value不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。

value只能由中文,字母,数字,“-”,“_”,“.”组成。

表17 VaultBindRules

参数

参数类型

描述

tags

Array of BindRulesTags objects

按tags过滤自动绑定的资源

最小长度:0

最大长度:5

数组长度:0 - 5

表18 BindRulesTags

参数

参数类型

描述

key

String

key不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。

key只能由中文,字母,数字,“-”,“_”组成。

value

String

value不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”。

value只能由中文,字母,数字,“-”,“_”,“.”组成。

表19 CbcOrderResult

参数

参数类型

描述

cloudServiceId

String

云服务ID

orderId

String

订单ID

subscribeResult

Integer

订购结果,1:成功;0:失败

resourceId

String

包周期资源预生成资源id。

状态码: 400

表20 响应Body参数

参数

参数类型

描述

error_code

String

请参见错误码

error_msg

String

错误信息

请求示例

  • 创建一个云服务器存储库,存储库容量为100G,按需计费,且同时绑定资源和添加标签。

    POST https://{endpoint}/v3/f841e01fd2b14e7fa41b6ae7aa6b0594/vaults
    
    {
      "vault" : {
        "backup_policy_id" : "6dd81d7d-a4cb-443e-b8ed-1af0bd3a261b",
        "billing" : {
          "cloud_type" : "public",
          "consistent_level" : "crash_consistent",
          "object_type" : "server",
          "protect_type" : "backup",
          "size" : 100,
          "charging_mode" : "post_paid",
          "is_auto_renew" : false,
          "is_auto_pay" : false,
          "console_url" : "https://console.demo.com/cbr/?agencyId=97fcd896b7914cb98f553a087232e243&region=testregion/cbr/manager/csbs/vaultList"
        },
        "description" : "vault_description",
        "name" : "vault_name",
        "resources" : [ {
          "extra_info" : {
            "exclude_volumes" : [ "43a320a5-3efd-4568-b1aa-8dd9183cc64b" ]
          },
          "id" : "23a320a5-3efd-4568-b1aa-8dd9183cc64c",
          "type" : "OS::Nova::Server"
        } ],
        "tags" : [ {
          "key" : "key01",
          "value" : "value01"
        } ],
        "enterprise_project_id" : "0"
      }
    }
  • 创建一个云硬盘备份存储库,存储库容量为40G,按需计费。

    POST https://{endpoint}/v3/f841e01fd2b14e7fa41b6ae7aa6b0594/vaults
    
    {
      "vault" : {
        "billing" : {
          "consistent_level" : "crash_consistent",
          "object_type" : "disk",
          "protect_type" : "backup",
          "size" : 40,
          "charging_mode" : "post_paid",
          "is_auto_renew" : false,
          "is_auto_pay" : false
        },
        "name" : "test",
        "resources" : [ ]
      }
    }

响应示例

状态码: 200

OK

{
  "vault" : {
    "provider_id" : "0daac4c5-6707-4851-97ba-169e36266b66",
    "description" : "vault_description",
    "tags" : [ {
      "value" : "value01",
      "key" : "key01"
    } ],
    "enterprise_project_id" : 0,
    "auto_bind" : false,
    "id" : "ad7627ae-5b0b-492e-b6bd-cd809b745197",
    "user_id" : "38d65be2ecd840d19046e239e841a734",
    "name" : "vault_name",
    "billing" : {
      "status" : "available",
      "used" : 0,
      "protect_type" : "backup",
      "object_type" : "server",
      "allocated" : 40,
      "spec_code" : "vault.backup.server.normal",
      "size" : 100,
      "cloud_type" : "public",
      "consistent_level" : "crash_consistent",
      "charging_mode" : "post_paid"
    },
    "created_at" : "2019-05-23T12:51:10.071+00:00",
    "project_id" : "fc347bc64ccd4589ae52e4f44b7433c7",
    "resources" : [ {
      "name" : "ecs-b977-0002",
      "backup_size" : 0,
      "protect_status" : "available",
      "backup_count" : 0,
      "extra_info" : {
        "exclude_volumes" : [ "1855eb9a-2b5e-4938-a9f0-aea08b6f9243", "5a51e8b3-2f65-4045-896f-f8ffae14b064" ]
      },
      "type" : "OS::Nova::Server",
      "id" : "23a320a5-3efd-4568-b1aa-8dd9183cc64c",
      "size" : 40
    } ]
  }
}

SDK代码示例

SDK代码示例如下。

  • 创建一个云服务器存储库,存储库容量为100G,按需计费,且同时绑定资源和添加标签。

     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
    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 CreateVaultSolution {
    
        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();
            CreateVaultRequest request = new CreateVaultRequest();
            VaultCreateReq body = new VaultCreateReq();
            List<Tag> listVaultTags = new ArrayList<>();
            listVaultTags.add(
                new Tag()
                    .withKey("key01")
                    .withValue("value01")
            );
            List<String> listExtraInfoExcludeVolumes = new ArrayList<>();
            listExtraInfoExcludeVolumes.add("43a320a5-3efd-4568-b1aa-8dd9183cc64b");
            ResourceExtraInfo extraInfoResources = new ResourceExtraInfo();
            extraInfoResources.withExcludeVolumes(listExtraInfoExcludeVolumes);
            List<ResourceCreate> listVaultResources = new ArrayList<>();
            listVaultResources.add(
                new ResourceCreate()
                    .withExtraInfo(extraInfoResources)
                    .withId("23a320a5-3efd-4568-b1aa-8dd9183cc64c")
                    .withType("OS::Nova::Server")
            );
            BillingCreate billingVault = new BillingCreate();
            billingVault.withCloudType(BillingCreate.CloudTypeEnum.fromValue("public"))
                .withConsistentLevel(BillingCreate.ConsistentLevelEnum.fromValue("crash_consistent"))
                .withObjectType(BillingCreate.ObjectTypeEnum.fromValue("server"))
                .withProtectType(BillingCreate.ProtectTypeEnum.fromValue("backup"))
                .withSize(100)
                .withChargingMode(BillingCreate.ChargingModeEnum.fromValue("post_paid"))
                .withIsAutoRenew(false)
                .withIsAutoPay(false)
                .withConsoleUrl("https://console.demo.com/cbr/?agencyId=97fcd896b7914cb98f553a087232e243&region=testregion/cbr/manager/csbs/vaultList");
            VaultCreate vaultbody = new VaultCreate();
            vaultbody.withBackupPolicyId("6dd81d7d-a4cb-443e-b8ed-1af0bd3a261b")
                .withBilling(billingVault)
                .withDescription("vault_description")
                .withName("vault_name")
                .withResources(listVaultResources)
                .withTags(listVaultTags)
                .withEnterpriseProjectId("0");
            body.withVault(vaultbody);
            request.withBody(body);
            try {
                CreateVaultResponse response = client.createVault(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());
            }
        }
    }
    
  • 创建一个云硬盘备份存储库,存储库容量为40G,按需计费。

     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 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 CreateVaultSolution {
    
        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();
            CreateVaultRequest request = new CreateVaultRequest();
            VaultCreateReq body = new VaultCreateReq();
            BillingCreate billingVault = new BillingCreate();
            billingVault.withConsistentLevel(BillingCreate.ConsistentLevelEnum.fromValue("crash_consistent"))
                .withObjectType(BillingCreate.ObjectTypeEnum.fromValue("disk"))
                .withProtectType(BillingCreate.ProtectTypeEnum.fromValue("backup"))
                .withSize(40)
                .withChargingMode(BillingCreate.ChargingModeEnum.fromValue("post_paid"))
                .withIsAutoRenew(false)
                .withIsAutoPay(false);
            VaultCreate vaultbody = new VaultCreate();
            vaultbody.withBilling(billingVault)
                .withName("test");
            body.withVault(vaultbody);
            request.withBody(body);
            try {
                CreateVaultResponse response = client.createVault(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());
            }
        }
    }
    
  • 创建一个云服务器存储库,存储库容量为100G,按需计费,且同时绑定资源和添加标签。

     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
    # 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 = CreateVaultRequest()
            listTagsVault = [
                Tag(
                    key="key01",
                    value="value01"
                )
            ]
            listExcludeVolumesExtraInfo = [
                "43a320a5-3efd-4568-b1aa-8dd9183cc64b"
            ]
            extraInfoResources = ResourceExtraInfo(
                exclude_volumes=listExcludeVolumesExtraInfo
            )
            listResourcesVault = [
                ResourceCreate(
                    extra_info=extraInfoResources,
                    id="23a320a5-3efd-4568-b1aa-8dd9183cc64c",
                    type="OS::Nova::Server"
                )
            ]
            billingVault = BillingCreate(
                cloud_type="public",
                consistent_level="crash_consistent",
                object_type="server",
                protect_type="backup",
                size=100,
                charging_mode="post_paid",
                is_auto_renew=False,
                is_auto_pay=False,
                console_url="https://console.demo.com/cbr/?agencyId=97fcd896b7914cb98f553a087232e243&region=testregion/cbr/manager/csbs/vaultList"
            )
            vaultbody = VaultCreate(
                backup_policy_id="6dd81d7d-a4cb-443e-b8ed-1af0bd3a261b",
                billing=billingVault,
                description="vault_description",
                name="vault_name",
                resources=listResourcesVault,
                tags=listTagsVault,
                enterprise_project_id="0"
            )
            request.body = VaultCreateReq(
                vault=vaultbody
            )
            response = client.create_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)
    
  • 创建一个云硬盘备份存储库,存储库容量为40G,按需计费。

     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
    # 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 = CreateVaultRequest()
            billingVault = BillingCreate(
                consistent_level="crash_consistent",
                object_type="disk",
                protect_type="backup",
                size=40,
                charging_mode="post_paid",
                is_auto_renew=False,
                is_auto_pay=False
            )
            vaultbody = VaultCreate(
                billing=billingVault,
                name="test"
            )
            request.body = VaultCreateReq(
                vault=vaultbody
            )
            response = client.create_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)
    
  • 创建一个云服务器存储库,存储库容量为100G,按需计费,且同时绑定资源和添加标签。

     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
    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.CreateVaultRequest{}
    	var listTagsVault = []model.Tag{
            {
                Key: "key01",
                Value: "value01",
            },
        }
    	var listExcludeVolumesExtraInfo = []string{
            "43a320a5-3efd-4568-b1aa-8dd9183cc64b",
        }
    	extraInfoResources := &model.ResourceExtraInfo{
    		ExcludeVolumes: &listExcludeVolumesExtraInfo,
    	}
    	var listResourcesVault = []model.ResourceCreate{
            {
                ExtraInfo: extraInfoResources,
                Id: "23a320a5-3efd-4568-b1aa-8dd9183cc64c",
                Type: "OS::Nova::Server",
            },
        }
    	cloudTypeBilling:= model.GetBillingCreateCloudTypeEnum().PUBLIC
    	chargingModeBilling:= model.GetBillingCreateChargingModeEnum().POST_PAID
    	isAutoRenewBilling:= false
    	isAutoPayBilling:= false
    	consoleUrlBilling:= "https://console.demo.com/cbr/?agencyId=97fcd896b7914cb98f553a087232e243&region=testregion/cbr/manager/csbs/vaultList"
    	billingVault := &model.BillingCreate{
    		CloudType: &cloudTypeBilling,
    		ConsistentLevel: model.GetBillingCreateConsistentLevelEnum().CRASH_CONSISTENT,
    		ObjectType: model.GetBillingCreateObjectTypeEnum().SERVER,
    		ProtectType: model.GetBillingCreateProtectTypeEnum().BACKUP,
    		Size: int32(100),
    		ChargingMode: &chargingModeBilling,
    		IsAutoRenew: &isAutoRenewBilling,
    		IsAutoPay: &isAutoPayBilling,
    		ConsoleUrl: &consoleUrlBilling,
    	}
    	backupPolicyIdVault:= "6dd81d7d-a4cb-443e-b8ed-1af0bd3a261b"
    	descriptionVault:= "vault_description"
    	enterpriseProjectIdVault:= "0"
    	vaultbody := &model.VaultCreate{
    		BackupPolicyId: &backupPolicyIdVault,
    		Billing: billingVault,
    		Description: &descriptionVault,
    		Name: "vault_name",
    		Resources: listResourcesVault,
    		Tags: &listTagsVault,
    		EnterpriseProjectId: &enterpriseProjectIdVault,
    	}
    	request.Body = &model.VaultCreateReq{
    		Vault: vaultbody,
    	}
    	response, err := client.CreateVault(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建一个云硬盘备份存储库,存储库容量为40G,按需计费。

     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
    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.CreateVaultRequest{}
    	chargingModeBilling:= model.GetBillingCreateChargingModeEnum().POST_PAID
    	isAutoRenewBilling:= false
    	isAutoPayBilling:= false
    	billingVault := &model.BillingCreate{
    		ConsistentLevel: model.GetBillingCreateConsistentLevelEnum().CRASH_CONSISTENT,
    		ObjectType: model.GetBillingCreateObjectTypeEnum().DISK,
    		ProtectType: model.GetBillingCreateProtectTypeEnum().BACKUP,
    		Size: int32(40),
    		ChargingMode: &chargingModeBilling,
    		IsAutoRenew: &isAutoRenewBilling,
    		IsAutoPay: &isAutoPayBilling,
    	}
    	vaultbody := &model.VaultCreate{
    		Billing: billingVault,
    		Name: "test",
    	}
    	request.Body = &model.VaultCreateReq{
    		Vault: vaultbody,
    	}
    	response, err := client.CreateVault(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

400

Bad Request

错误码

请参见错误码

分享:

    相关文档

    相关产品