数据库安全服务 DBSS-包年包月计费模式创建审计实例:Python

时间:2024-10-21 18:38:49

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)
support.huaweicloud.com/api-dbss/CreateInstancesPeriodOrder.html