/
c3mc-cloud-qcloud-clb-by-name
executable file
·44 lines (33 loc) · 1.34 KB
/
c3mc-cloud-qcloud-clb-by-name
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
#!/usr/bin/env /data/Software/mydan/python3/bin/python3
# -*- coding: utf-8 -*-
import sys
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.clb.v20180317 import clb_client, models
def get_clb_by_name(access_id, access_key, region, clb_name):
"""
输出qcloud clb的详情(json格式)
"""
cred = credential.Credential(access_id, access_key)
httpProfile = HttpProfile()
httpProfile.endpoint = "clb.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = clb_client.ClbClient(cred, region, clientProfile)
req = models.DescribeLoadBalancersRequest()
params = {
"LoadBalancerName": clb_name
}
req.from_json_string(json.dumps(params))
resp = client.DescribeLoadBalancers(req)
for item in resp.LoadBalancerSet:
if item.LoadBalancerName == clb_name:
return item
raise Exception("根据clb_name {} 未找到clb".format(clb_name))
def main(access_id, access_key, region, instance_name):
data = get_clb_by_name(access_id, access_key, region, instance_name)
print(str(data))
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])