/
c3mc-query-qcloud-cbs-price
executable file
·58 lines (47 loc) · 1.76 KB
/
c3mc-query-qcloud-cbs-price
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
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.cbs.v20170312 import cbs_client, models
def get_cbs_price(access_id, access_key, region, size):
cred = credential.Credential(access_id, access_key)
httpProfile = HttpProfile()
httpProfile.endpoint = "cbs.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = cbs_client.CbsClient(cred, region, clientProfile)
req = models.InquiryPriceCreateDisksRequest()
params = {
"DiskChargeType": "PREPAID",
"DiskCount": 1,
"DiskSize": int(size),
"DiskType": "CLOUD_BASIC",
"DiskChargePrepaid": {
"RenewFlag": "DISABLE_NOTIFY_AND_MANUAL_RENEW",
"Period": 1
}
}
req.from_json_string(json.dumps(params))
try:
resp = client.InquiryPriceCreateDisks(req)
except Exception as e:
if "ResourceUnavailable" in str(e):
return ""
else:
raise e
# 单位: 元
return "{} {}".format(resp.DiskPrice.DiscountPrice, "CNY")
def get_price_info(access_id, access_key, region, size):
price = get_cbs_price(access_id, access_key, region, size)
if price == "":
return None
return "qcloud-cvm-volume@{}@{};{}".format(region, size, price)
def main(access_id, access_key, region, size):
data = get_price_info(access_id, access_key, region, size)
if data is not None:
print(data)
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])