...
|
...
|
@@ -53,11 +53,11 @@ class LBSwitch: |
|
|
ret_az2 = self.modify_alb_weight(lb_id=self.az2_lb_id, domain="*.yoho.cn", ip_weight_dict=ip_weight_dict)
|
|
|
print("switch all incoming request from az2 to az1 result: %s" % ret_az2)
|
|
|
|
|
|
# az
|
|
|
# az1 公网流量切换到az1
|
|
|
ret_az1 = self.modify_clb_weight(lb_id=self.az1_lb_id, ip_weight_dict=ip_weight_dict)
|
|
|
print("switch all incoming request from az1 to az1 result: %s" % ret_az1)
|
|
|
|
|
|
return ret_az1 & ret_az2
|
|
|
return ret_az1 and ret_az2
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -137,7 +137,7 @@ class LBSwitch: |
|
|
# see qcloud api details at: https://cloud.tencent.com/document/product/214/8987
|
|
|
instance_weight = {} # instance_id --> weight
|
|
|
instance_port = {} # instance_id --> port
|
|
|
listener_ids = [] # all linsters
|
|
|
listener_ids = {} # all linsters
|
|
|
|
|
|
api = QcloudApi(secretId=self.SecretId, secretKey=self.SecretKey)
|
|
|
lb_info = api.do_query(params={'Action': 'DescribeForwardLBBackends', 'loadBalancerId': lb_id}, req_url=QcloudApi.URLS_lb)
|
...
|
...
|
@@ -146,7 +146,7 @@ class LBSwitch: |
|
|
for listener in lb_info['data']:
|
|
|
for rule in listener['rules']:
|
|
|
if rule['domain'] == domain: # domain match
|
|
|
listener_ids.append(listener['listenerId'])
|
|
|
listener_ids[listener['listenerId']] = listener['protocolType']
|
|
|
for backend in rule['backends']:
|
|
|
instance_port[backend['unInstanceId']] = backend['port']
|
|
|
if backend['lanIp'] in ip_weight_dict.keys():
|
...
|
...
|
@@ -162,7 +162,7 @@ class LBSwitch: |
|
|
# 修改七层负载均衡器的权重
|
|
|
# see details at: https://cloud.tencent.com/document/product/214/8978
|
|
|
return_code = []
|
|
|
for lis_id in listener_ids:
|
|
|
for lis_id in listener_ids.keys():
|
|
|
params = {'Action': 'ModifyForwardSeventhBackends', 'loadBalancerId': lb_id,
|
|
|
'listenerId': lis_id, 'domain': domain}
|
|
|
i = 1
|
...
|
...
|
@@ -173,7 +173,7 @@ class LBSwitch: |
|
|
i = i + 1
|
|
|
|
|
|
rsp = api.do_query(params, req_url=QcloudApi.URLS_lb)
|
|
|
print(u"response code: %s . success change domain: %s for lis_id : %s. wait for 10s" % (rsp['code'], domain, lis_id))
|
|
|
print(u"response code: %s . success change domain: %s for listener : %s. wait for 10s" % (rsp['code'], domain, listener_ids[lis_id]))
|
|
|
return_code.append(rsp['code'])
|
|
|
time.sleep(10)
|
|
|
return return_code.count(0) == len(return_code)
|
...
|
...
|
@@ -183,7 +183,7 @@ lbswitch = LBSwitch(secretId="AKID6dwpKadiQgbDpXDtyNhppIHPO5qPv5GK", secretKey=" |
|
|
az1_lb_id="lb-e14oxiq3", az2_lb_id="lb-e14oxiq3", az3_lb_id="lb-e14oxiq3")
|
|
|
|
|
|
#ret = lbswitch.modify_clb_weight(lb_id="lb-e14oxiq3", ip_weight_dict={"10.66.104.15": 10, "10.66.104.13":20})
|
|
|
ret = lbswitch.modify_alb_weight(lb_id="lb-fodpm611", domain="*.yoho.cn", ip_weight_dict={"10.66.104.15": 10, "10.66.104.13":20})
|
|
|
ret = lbswitch.modify_alb_weight(lb_id="lb-fodpm611", domain="*.yoho.cn", ip_weight_dict={"10.66.0.2": 10, "10.66.0.3": 10})
|
|
|
|
|
|
print ret
|
|
|
|
...
|
...
|
|