用python修改腾讯云负载均衡的权重

1.一个location有四个实例,每次修改一半的权重

[root@master dxw-test]# cat modify_lb.py
import json,sys,time
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.clb.v20180317 import clb_client, models

cred = credential.Credential("AKnie5FCvv2IshifDCDd8vUqvlNlv4sbgSY6", "TilniWeGijZ9T9cbaUikW1CDyUsivRh5le")
httpProfile = HttpProfile()
httpProfile.endpoint = "clb.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = clb_client.ClbClient(cred, "ap-beijing", clientProfile)
my_list = ["loc-7kw3jt39","ins-hci5ed0h",13]
location_list=['loc-bfhc80bl','loc-7kw3jt39','loc-necbmi01']
instance_list=['ins-hci5ed0h','ins-jqwmulxj']

def modify_action(my_list):
     try:
         req = models.ModifyTargetWeightRequest()
         params = {
             "Targets": [
                 {
                     "Type": "CVM",
                     "InstanceId": my_list[1],
                     "Port": 30094,
                     "Weight": my_list[3]
                 },
                 {
                     "Type": "CVM",
                     "InstanceId": my_list[2],
                     "Port": 30110,
                     "Weight": my_list[3]
                 }
             ],
             "LoadBalancerId": "lb-7gdw7wqr",
             "ListenerId": "lbl-p7ynx349",
             "LocationId": my_list[0],
         }
         req.from_json_string(json.dumps(params))

         resp = client.ModifyTargetWeight(req)
         print(resp.to_json_string())

     except TencentCloudSDKException as err:
         print(err)

print(sys.argv[1],sys.argv[2])
#modify a row, change weigh of row a from now to begin
#list_a0=["LocationId","InstanceId1","InstanceId2",weigh]:q
if sys.argv[1]=='admin':
   list_admin=["loc-bfhc80bl","ins-hci5ed0h","ins-jqwmulxj",int(sys.argv[2])]
   modify_action(list_admin)


if sys.argv[1]=='biz':
   list_biz=["loc-7kw3jt39","ins-hci5ed0h","ins-jqwmulxj",int(sys.argv[2])]
   modify_action(list_biz)

 

上一篇:PCL文件类型转换


下一篇:Zygote——Android系统中java世界的受精卵(一、C/C++中的Zygote)