文档首页/ 数据库安全服务 DBSS/ API参考/ API/ 审计实例/ 包年包月计费模式创建审计实例
更新时间:2024-11-04 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。 通过调用IAM服务查询用户Token接口获取(响应消息头中X-Subject-Token的值)。

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

实例名称。取值范围:

  • 只能由中文字符、英文字母、数字、下划线、中划线组成,且长度小于等于64个字符。

flavor_ref

String

云服务器使用的规格ID

vpc_id

String

虚拟私有云的ID

availability_zone

String

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

enterprise_project_id

String

企业项目ID。对接EPS必输。

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":{"主机名称":"value1","规格":"value2","虚拟私有云":"value3","子网":"value4"},"en-us":{"Instance Name":"value1","Edition":"value2","VPC":"value3","Subnet":"value4"}}}

表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

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

请求示例

/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" : "xx-xx",
  "comment" : "",
  "region" : "xx-xx",
  "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-xxxxxxx-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\":{},\"en-us\":{\"instance Name\":\"DBSS-test\",\"VPC\":\"default_vpc\",\"Subnet\":\"subnet-af32\"}}}"
  } ],
  "promotion_info" : "",
  "enterprise_project_id" : "0",
  "tags" : [ {
    "key" : "key_test",
    "value" : "1"
  } ]
}

响应示例

状态码: 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
93
94
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");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        DbssClient client = DbssClient.newBuilder()
                .withCredential(auth)
                .withRegion(DbssRegion.valueOf("<YOUR REGION>"))
                .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-xxxxxxx-0--0")
                .withCloudServiceType("hws.service.type.dbss")
                .withResourceType("hws.resource.type.dbss")
                .withResourceSpecCode("dbss.bypassaudit.low")
                .withProductSpecDesc("{"specDesc":{"zh-cn":{},"en-us":{"instance Name":"DBSS-test","VPC":"default_vpc","Subnet":"subnet-af32"}}}")
        );
        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("xx-xx");
        body.withComment("");
        body.withSecurityGroups(listbodySecurityGroups);
        body.withNics(listbodyNics);
        body.withEnterpriseProjectId("0");
        body.withAvailabilityZone("xx-xx");
        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
75
76
# coding: utf-8

import os
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.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = DbssClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DbssRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateInstancesPeriodOrderRequest()
        listTagsbody = [
            KeyValueBean(
                key="key_test",
                value="1"
            )
        ]
        listProductInfosbody = [
            CreateInstancePeriodRequestProductInfos(
                product_id="00301-xxxxxxx-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":{},"en-us":{"instance Name":"DBSS-test","VPC":"default_vpc","Subnet":"subnet-af32"}}}"
            )
        ]
        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="xx-xx",
            comment="",
            security_groups=listSecurityGroupsbody,
            nics=listNicsbody,
            enterprise_project_id="0",
            availability_zone="xx-xx",
            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
84
85
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")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := dbss.NewDbssClient(
        dbss.DbssClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateInstancesPeriodOrderRequest{}
	var listTagsbody = []model.KeyValueBean{
        {
            Key: "key_test",
            Value: "1",
        },
    }
	var listProductInfosbody = []model.CreateInstancePeriodRequestProductInfos{
        {
            ProductId: "00301-xxxxxxx-0--0",
            CloudServiceType: "hws.service.type.dbss",
            ResourceType: "hws.resource.type.dbss",
            ResourceSpecCode: "dbss.bypassaudit.low",
            ProductSpecDesc: "{"specDesc":{"zh-cn":{},"en-us":{"instance Name":"DBSS-test","VPC":"default_vpc","Subnet":"subnet-af32"}}}",
        },
    }
	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: "xx-xx",
		Comment: &commentCreateInstancePeriodRequest,
		SecurityGroups: listSecurityGroupsbody,
		Nics: listNicsbody,
		EnterpriseProjectId: "0",
		AvailabilityZone: "xx-xx",
		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

服务端错误

错误码

请参见错误码

相关文档