Help Center/ Database Security Service/ API Reference/ API/ Audit Instance/ Creating an Audit Instance in Yearly/Monthly Billing Mode
Updated on 2024-11-01 GMT+08:00

Creating an Audit Instance in Yearly/Monthly Billing Mode

Function

This API is used to create an audit instance in yearly/monthly billing mode.

Calling Method

For details, see Calling APIs.

URI

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

Table 1 URI parameter

Parameter

Mandatory

Parameter Type

Description

project_id

Yes

String

Project ID.

Request Parameter

Table 2 Request header parameter

Parameter

Mandatory

Parameter Type

Description

X-Auth-Token

Yes

String

User token. The token can be queried by calling the IAM API. (The token is the value of X-Subject-Token in the response header.)

Table 3 Request body parameter

Parameter

Mandatory

Parameter Type

Description

name

Yes

String

Instance name. The options are as follows:

  • A name must contain 1 to 64 characters including digits, letters, underscores (_), and hyphens (-),

flavor_ref

Yes

String

Specifies the ID of the specifications used by the ECS.

vpc_id

Yes

String

VPC ID

availability_zone

Yes

String

Availability zone to which the ECS belongs. (Primary and secondary AZs are separated by commas. Example: az1.dc1,az2.dc2)

enterprise_project_id

No

String

Specifies the ID of the enterprise project Mandatory for interconnecting with EPS.

nics

Yes

Array of nics objects

NIC of the ECS

security_groups

Yes

Array of security_groups objects

Information about the security group to which the ECS belongs.

comment

No

String

Indicates the remarks.

region

Yes

String

ID of the region where the ECS is located.

cloud_service_type

Yes

String

Service type:

  • hws.service.type.dbss

charging_mode

Yes

Integer

Billing mode:

  • 0: yearly/monthly
  • 1: pay-per-use

period_type

Yes

Integer

Subscription period type. The value can be:

  • 0: day
  • 1: week
  • 2: month
  • 3: year
  • 4: hour
  • 5: absolute time

period_num

Yes

Integer

Number of subscription periods

subscription_num

Yes

Integer

Number of subscriptions.

Only one set of DBSS can be subscribed to.

product_infos

Yes

Array of product_infos objects

Product list.

tags

No

Array of KeyValueBean objects

Resource tag

promotion_info

No

String

Discount information

is_auto_renew

No

Integer

Auto-Renewal

  • 1: automatic renewal
  • 0: no
Table 4 nics

Parameter

Mandatory

Parameter Type

Description

subnet_id

Yes

String

ID of the subnet on which the NIC works.

ip_address

No

String

IP address. If the value of this parameter is left blank or is set to an empty string, an IP address is automatically assigned.

Table 5 security_groups

Parameter

Mandatory

Parameter Type

Description

id

Yes

String

Specifies the ID of the security group corresponding to the ECS. This ID takes effect for the NIC configured on the ECS.

Table 6 product_infos

Parameter

Mandatory

Parameter Type

Description

product_id

Yes

String

Product ID.

cloud_service_type

Yes

String

Service Type:

  • hws.service.type.dbss

resource_type

Yes

String

Resource type:

  • hws.resource.type.dbss

resource_spec_code

Yes

String

Resource specifications: - dbss.bypassaudit.low-dbss.bypassaudit.medium-dbss.bypassaudit.high

product_spec_desc

No

String

Product specification description, including the host name, specifications, VPC, and subnet. JSON string format: {"specDesc":{"zh-cn":{" Host name ":"value1"," Specification ":"value2"," VPC ":"value3"," Subnet ":"value4"},"en-us":{"Instance Name":"value1","Edition":"value2","VPC":"value3","Subnet":"value4"}}}

Table 7 KeyValueBean

Parameter

Mandatory

Parameter Type

Description

key

Yes

String

Tag key.

value

No

String

Value

Response Parameters

Status code: 200

Table 8 Response body parameter

Parameter

Parameter Type

Description

description

String

Description

code

String

Returned code

order_id

String

Specifies an order ID.

Status code: 400

Table 9 Response body parameter

Parameter

Parameter Type

Description

error

Object

Error message.

Table 10 ErrorDetail

Parameter

Parameter Type

Description

error_code

String

Error code

error_msg

String

Error message

Status code: 403

Table 11 Response body parameters

Parameter

Parameter Type

Description

error

Object

Error message.

Table 12 ErrorDetail

Parameter

Parameter Type

Description

error_code

String

Error code

error_msg

String

Error message

Status code: 500

Table 13 Response body parameter

Parameter

Parameter Type

Description

error

Object

Error message.

Table 14 ErrorDetail

Parameter

Parameter Type

Description

error_code

String

Error code

error_msg

String

Error message

Example request

/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"
  } ]
}

Response Examples

Status code: 200

Success

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

Status code: 400

Failed

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

Example SDK Code

The sample code is as follows.

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

More

For more SDK code examples in various programming languages, see the Sample Code tab on the right of the API Explorer page, which can automatically generate the corresponding SDK code examples.

Status Code

Status Code

Description

200

Success

400

Failed

403

Authentication failed.

500

Server error.

Error Codes

For details, see Error Codes.