文档首页> 数据库安全服务 DBSS> API参考> API> 实例购买查询接口> 包年包月计费模式创建审计实例
更新时间:2024-04-11 GMT+08:00
分享

包年包月计费模式创建审计实例

功能介绍

包年包月计费模式创建审计实例

调用方法

请参见如何调用API

URI

POST /v2/{project_id}/dbss/audit/charge/period/order

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token

表3 请求Body参数

参数

是否必选

参数类型

描述

flavor_ref

String

云服务器使用的规格ID

name

String

云服务器名称。 取值范围: 只能由中文字符、英文字母、数字、下划线、中划线组成,且长度小于等于64个字符。 创建的云服务器数量大于1时,长度小于等于59个字符

vpc_id

String

VPC的ID

availability_zone

String

云服务器对应可用分区信息。(两个主备分区,中间用“,”分割,例如az1.dc1,az2.dc2)

enterprise_project_id

String

企业项目ID

nics

Array of nics objects

云服务器对应的网卡信息

security_groups

Array of security_groups objects

云服务器对应安全组信息

comment

String

备注信息

region

String

云服务器所在区域ID

cloud_service_type

String

服务类型: 默认hws.service.type.dbss

charging_mode

Integer

计费模式: 0:包周期计费 1:按需计费

period_type

Integer

订购周期类型: 0:天; 1:周; 2:月; 3:年; 4:小时; 5:绝对时间

period_num

Integer

订购周期数

subscription_num

Integer

订购数量: DBSS只支持订购1套,不支持多套

product_infos

Array of product_infos objects

产品信息列表

tags

Array of KeyValueBean objects

资源标签

promotion_info

String

折扣信息

is_auto_renew

Integer

自动续费 1表示自动续费,0表示不自动续费

表4 nics

参数

是否必选

参数类型

描述

subnet_id

String

网卡对应的子网ID

ip_address

String

IP地址,不填或空字符串为自动分配

表5 security_groups

参数

是否必选

参数类型

描述

id

String

云服务器对应的安全组ID,会对创建云服务器中配置的网卡生效

表6 product_infos

参数

是否必选

参数类型

描述

product_id

String

产品ID

cloud_service_type

String

服务类型: 默认hws.service.type.dbss

resource_type

String

资源类型: 默认hws.resource.type.dbss

resource_spec_code

String

资源规格:dbss.bypassaudit.low、dbss.bypassaudit.medium、dbss.bypassaudit.high

product_spec_desc

String

产品规格描述, json字符串格式 :{"specDesc":{"zh-cn":{"key1":"value1"},"en-us":{"key1":"value1"}}}

表7 KeyValueBean

参数

是否必选

参数类型

描述

key

String

value

String

响应参数

状态码: 200

表8 响应Body参数

参数

参数类型

描述

description

String

描述

code

String

返回码

order_id

String

订单ID

状态码: 400

表9 响应Body参数

参数

参数类型

描述

error

Object

错误信息返回体。

表10 ErrorDetail

参数

参数类型

描述

error_code

String

错误请求返回的错误码。

error_msg

String

错误请求返回的错误信息。

状态码: 403

表11 响应Body参数

参数

参数类型

描述

error

Object

错误信息返回体。

表12 ErrorDetail

参数

参数类型

描述

error_code

String

错误请求返回的错误码。

error_msg

String

错误请求返回的错误信息。

状态码: 500

表13 响应Body参数

参数

参数类型

描述

error

Object

错误信息返回体。

表14 ErrorDetail

参数

参数类型

描述

error_code

String

错误请求返回的错误码。

error_msg

String

错误请求返回的错误信息。

请求示例

创建一个包周期计费"chargin_mode : 0"的实例,版本为基础版:"resource_spec_code" : "dbss.bypassaudit.low"。

/v2/{project_id}/dbss/audit/charge/period/order

{
  "flavor_ref" : "st6.xlarge.4",
  "name" : "DBSS-acc3",
  "vpc_id" : "4c035747-f77b-4c6d-b23b-cb3a2b96c7e6",
  "availability_zone" : "cn-north-7c",
  "comment" : "",
  "region" : "cn-north-7",
  "nics" : [ {
    "subnet_id" : "6201dcf2-1374-43ec-ae8b-78b4081572d3"
  } ],
  "security_groups" : [ {
    "id" : "04088976-9c63-4e6b-9070-84e6a30c782b"
  } ],
  "cloud_service_type" : "hws.service.type.dbss",
  "charging_mode" : 0,
  "period_type" : 2,
  "period_num" : 1,
  "subscription_num" : 1,
  "is_auto_renew" : 0,
  "product_infos" : [ {
    "product_id" : "00301-225396-0--0",
    "cloud_service_type" : "hws.service.type.dbss",
    "resource_type" : "hws.resource.type.dbss",
    "resource_spec_code" : "dbss.bypassaudit.low",
    "product_spec_desc" : "{\"specDesc\":{\"zh-cn\":{\"key1\":\"value1\"},\"en-us\":{\"key1\":\"value1\"}}}"
  } ],
  "promotion_info" : "",
  "enterprise_project_id" : "0",
  "tags" : [ {
    "key" : "key_test",
    "value" : "1"
  } ]
}
创建一个包周期计费"chargin_mode : 0"的实例,版本为专业版:"resource_spec_code" : "dbss.bypassaudit.medium"。
{
    "flavor_ref": "c6.2xlarge.2",
    "name": "DBSS-test",
    "vpc_id": "4c035747-f77b-4c6d-b23b-cb3a2b96c7e6",
    "availability_zone": "cn-north-7b",
    "comment": "",
    "region": "cn-north-7",
    "nics": [
      {
        "subnet_id": "6201dcf2-1374-43ec-ae8b-78b4081572d3"
      }
    ],
    "security_groups": [
      {
        "id": "59c45017-a484-481b-8440-18c2214ccb06"
      }
    ],
    "cloud_service_type": "hws.service.type.dbss",
    "charging_mode": 0,
    "period_type": 2,
    "period_num": 1,
    "subscription_num": 1,
    "is_auto_renew": 0,
    "product_infos": [
      {
        "product_id": "00301-225396-0--0",
        "cloud_service_type": "hws.service.type.dbss",
        "resource_type": "hws.resource.type.dbss",
        "resource_spec_code": "dbss.bypassaudit.medium",
        "product_spec_desc": "{\"specDesc\":{\"zh-cn\":{\"key1\":\"value1\"},\"en-us\":{\"key1\":\"value1\"}}}"     
       }
    ],
    "promotion_info": "",
    "enterprise_project_id": "0"
  }

响应示例

状态码: 200

成功

{
  "description" : "Success",
  "code" : "0",
  "order_id" : "CS1710190909OGQIS"
}

状态码: 400

失败

{
  "error" : {
    "error_code" : "DBSS.XXXX",
    "error_msg" : "XXX"
  }
}

SDK代码示例

SDK代码示例如下。

Java

 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
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.dbss.v1.region.DbssRegion;
import com.huaweicloud.sdk.dbss.v1.*;
import com.huaweicloud.sdk.dbss.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateInstancesPeriodOrderSolution {

    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);

        DbssClient client = DbssClient.newBuilder()
                .withCredential(auth)
                .withRegion(DbssRegion.valueOf("cn-north-4"))
                .build();
        CreateInstancesPeriodOrderRequest request = new CreateInstancesPeriodOrderRequest();
        CreateInstancePeriodRequest body = new CreateInstancePeriodRequest();
        List<KeyValueBean> listbodyTags = new ArrayList<>();
        listbodyTags.add(
            new KeyValueBean()
                .withKey("key_test")
                .withValue("1")
        );
        List<CreateInstancePeriodRequestProductInfos> listbodyProductInfos = new ArrayList<>();
        listbodyProductInfos.add(
            new CreateInstancePeriodRequestProductInfos()
                .withProductId("00301-225396-0--0")
                .withCloudServiceType("hws.service.type.dbss")
                .withResourceType("hws.resource.type.dbss")
                .withResourceSpecCode("dbss.bypassaudit.low")
                .withProductSpecDesc("test")
        );
        List<CreateInstancePeriodRequestSecurityGroups> listbodySecurityGroups = new ArrayList<>();
        listbodySecurityGroups.add(
            new CreateInstancePeriodRequestSecurityGroups()
                .withId("04088976-9c63-4e6b-9070-84e6a30c782b")
        );
        List<CreateInstancePeriodRequestNics> listbodyNics = new ArrayList<>();
        listbodyNics.add(
            new CreateInstancePeriodRequestNics()
                .withSubnetId("6201dcf2-1374-43ec-ae8b-78b4081572d3")
        );
        body.withIsAutoRenew(0);
        body.withPromotionInfo("");
        body.withTags(listbodyTags);
        body.withProductInfos(listbodyProductInfos);
        body.withSubscriptionNum(1);
        body.withPeriodNum(1);
        body.withPeriodType(2);
        body.withChargingMode(0);
        body.withCloudServiceType("hws.service.type.dbss");
        body.withRegion("cn-north-7");
        body.withComment("");
        body.withSecurityGroups(listbodySecurityGroups);
        body.withNics(listbodyNics);
        body.withEnterpriseProjectId("0");
        body.withAvailabilityZone("cn-north-7c");
        body.withVpcId("4c035747-f77b-4c6d-b23b-cb3a2b96c7e6");
        body.withName("DBSS-acc3");
        body.withFlavorRef("st6.xlarge.4");
        request.withBody(body);
        try {
            CreateInstancesPeriodOrderResponse response = client.createInstancesPeriodOrder(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

 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
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdbss.v1.region.dbss_region import DbssRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdbss.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 = os.getenv("CLOUD_SDK_AK")
    sk = os.getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = DbssClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DbssRegion.value_of("cn-north-4")) \
        .build()

    try:
        request = CreateInstancesPeriodOrderRequest()
        listTagsbody = [
            KeyValueBean(
                key="key_test",
                value="1"
            )
        ]
        listProductInfosbody = [
            CreateInstancePeriodRequestProductInfos(
                product_id="00301-225396-0--0",
                cloud_service_type="hws.service.type.dbss",
                resource_type="hws.resource.type.dbss",
                resource_spec_code="dbss.bypassaudit.low",
                product_spec_desc="test"
            )
        ]
        listSecurityGroupsbody = [
            CreateInstancePeriodRequestSecurityGroups(
                id="04088976-9c63-4e6b-9070-84e6a30c782b"
            )
        ]
        listNicsbody = [
            CreateInstancePeriodRequestNics(
                subnet_id="6201dcf2-1374-43ec-ae8b-78b4081572d3"
            )
        ]
        request.body = CreateInstancePeriodRequest(
            is_auto_renew=0,
            promotion_info="",
            tags=listTagsbody,
            product_infos=listProductInfosbody,
            subscription_num=1,
            period_num=1,
            period_type=2,
            charging_mode=0,
            cloud_service_type="hws.service.type.dbss",
            region="cn-north-7",
            comment="",
            security_groups=listSecurityGroupsbody,
            nics=listNicsbody,
            enterprise_project_id="0",
            availability_zone="cn-north-7c",
            vpc_id="4c035747-f77b-4c6d-b23b-cb3a2b96c7e6",
            name="DBSS-acc3",
            flavor_ref="st6.xlarge.4"
        )
        response = client.create_instances_period_order(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

 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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    dbss "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dbss/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dbss/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dbss/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 := dbss.NewDbssClient(
        dbss.DbssClientBuilder().
            WithRegion(region.ValueOf("cn-north-4")).
            WithCredential(auth).
            Build())

    request := &model.CreateInstancesPeriodOrderRequest{}
	var listTagsbody = []model.KeyValueBean{
        {
            Key: "key_test",
            Value: "1",
        },
    }
	var listProductInfosbody = []model.CreateInstancePeriodRequestProductInfos{
        {
            ProductId: "00301-225396-0--0",
            CloudServiceType: "hws.service.type.dbss",
            ResourceType: "hws.resource.type.dbss",
            ResourceSpecCode: "dbss.bypassaudit.low",
            ProductSpecDesc: "test",
        },
    }
	var listSecurityGroupsbody = []model.CreateInstancePeriodRequestSecurityGroups{
        {
            Id: "04088976-9c63-4e6b-9070-84e6a30c782b",
        },
    }
	var listNicsbody = []model.CreateInstancePeriodRequestNics{
        {
            SubnetId: "6201dcf2-1374-43ec-ae8b-78b4081572d3",
        },
    }
	isAutoRenewCreateInstancePeriodRequest:= int32(0)
	promotionInfoCreateInstancePeriodRequest:= ""
	commentCreateInstancePeriodRequest:= ""
	request.Body = &model.CreateInstancePeriodRequest{
		IsAutoRenew: &isAutoRenewCreateInstancePeriodRequest,
		PromotionInfo: &promotionInfoCreateInstancePeriodRequest,
		Tags: &listTagsbody,
		ProductInfos: listProductInfosbody,
		SubscriptionNum: int32(1),
		PeriodNum: int32(1),
		PeriodType: int32(2),
		ChargingMode: int32(0),
		CloudServiceType: "hws.service.type.dbss",
		Region: "cn-north-7",
		Comment: &commentCreateInstancePeriodRequest,
		SecurityGroups: listSecurityGroupsbody,
		Nics: listNicsbody,
		EnterpriseProjectId: "0",
		AvailabilityZone: "cn-north-7c",
		VpcId: "4c035747-f77b-4c6d-b23b-cb3a2b96c7e6",
		Name: "DBSS-acc3",
		FlavorRef: "st6.xlarge.4",
	}
	response, err := client.CreateInstancesPeriodOrder(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

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

状态码

状态码

描述

200

成功

400

失败

403

认证失败

500

服务端错误

错误码

请参见错误码

分享:

    相关文档

    相关产品