/
c3mc-bpm-option-qcloud-mysql-describe-engine-type-list
executable file
·58 lines (43 loc) · 1.53 KB
/
c3mc-bpm-option-qcloud-mysql-describe-engine-type-list
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
#!/usr/bin/env /data/Software/mydan/python3/bin/python3
# -*- coding: utf-8 -*-
import json
import sys
import subprocess
sys.path.append("/data/Software/mydan/Connector/lib/pp")
def get_data_list(access_id, access_key, region, zone, charge_type):
from c3mc_cloud_qcloud_cdb import QcloudCdb
res = QcloudCdb(access_id, access_key, region).describe_cdb_zone_config()
for region_item in res["DataResult"]["Regions"]:
if region_item["Region"] != region:
continue
for zone_item in region_item["RegionConfig"]:
if zone_item["Zone"] != zone:
continue
if charge_type not in zone_item["PayType"]:
return []
return zone_item["EngineType"]
return []
def main(params):
"""查询可用区列表"""
account = params["account"]
region = params["region"]
zone = params["zone"]
charge_type_str = params["charge_type"]
charge_type = "1" if charge_type_str == "按量计费" else "0"
key_info = json.loads(
subprocess.getoutput(f"c3mc-get-account-info qcloud {account}")
)
data_list = get_data_list(
key_info["access_id"],
key_info["access_key"],
region,
zone,
charge_type,
)
for item in data_list:
print(json.dumps({"id": item, "name": item}))
if __name__ == "__main__":
l = list(sys.stdin)
if not l or len(l) > 1:
raise type("WrongInputData", (Exception,), {})('数据格式不对, 需要一行json字符串"')
main(json.loads(l[0]))