Authored by chunhua.zhang

add

... ... @@ -38,24 +38,23 @@ yoho.switch
>2.可用区之间的网络出现故障。例如az1 <--> az2 网络不通; 切换方案:流量切换到主可用区
#### 1.1 流量切换到主可用区(AZ1)
#### 1.1 流量切换到主可用区(AZ1)
副可用区出现故障的场景,细分如下2个场景:
- 副可用区所在的外部负载均衡器正常: `LB Switch To AZ1` (AZ2流量从负载均衡器上切换到AZ1)
>1)AZ2公网流量切换到AZ1
>
>2)AZ1公网、内网(*.yoho.yohoops.org)流量切换到AZ1
- 副可用区所在的外部负载均衡器异常: `ASK Switch To AZ1` (问询服务器上将流量切换到AZ1)
#### 1.2 流量切换到副可用区(AZ2)
###### LB Switch to AZ1
>1)AZ2 外部负载均衡器(`lb-ivt5h95t`, `123.206.2.50`)上 `*.yoho.cn` 切换到AZ1
>1)AZ1公网流量、内网流量切换到AZ2
>
>2)AZ1 外部负载均衡器(`lb-09g87u8f`, `123.206.1.98`) 切换到AZ1
>2)AZ2公网流量切换到AZ2
###### ASK Switch To AZ1
#### 1.3 切换问询服务器流量到AZ1
> `curl -H "Host: dnsresolver.yohoops.org" "http://10.66.4.23/switchCloud?cloudType=1"`
>
... ...
... ... @@ -46,7 +46,7 @@ class QcloudApi:
sign = self.signature(params, req_url)
params['Signature'] = sign
response_dict = requests.post("https://" + req_url, data=params).json()
print("Query qcloud api success. params:\n %s \n" % (params))
print("call qcloud api success. params:\n %s \n" % (params))
print json.dumps(response_dict, indent=4, sort_keys=True)
return response_dict
... ...
... ... @@ -20,22 +20,27 @@ from ansible.inventory.manager import InventoryManager
demo:
lbswitch = LBSwitch(secretId="AKID6dwpxxxxxqPv5GK", secretKey="ACJxxxxBsQaW",
az1_lb_id="lb-e14oxiq3", az2_lb_id="lb-e14oxiq3", az3_lb_id="lb-e14oxiq3")
lbswitch.all_to_az1()
lbswitch = LBSwitch(secretId="AKID6dwpKadiQgbDpXDtyNhppIHPO5qPv5GK", secretKey="ACJkH9mg0DBA1PYpf0E7f3g534wBsQaW",
az1_lb_id="lb-dyh6eucn", az2_lb_id="lb-capto5b5", az3_lb_id="lb-capto5b5", az1_innerlb_id="lb-c26tgo5r")
# 全部流量切换到AZ1
ret = lbswitch.all_to_az1()
# 全部流量切换到AZ2
ret = lbswitch.all_to_az2()
"""
class LBSwitch:
def __init__(self, secretId, secretKey, az1_lb_id, az2_lb_id, az3_lb_id):
def __init__(self, secretId, secretKey, az1_lb_id, az2_lb_id, az3_lb_id, az1_innerlb_id):
self.SecretId = secretId
self.SecretKey = secretKey
self.az1_lb_id = az1_lb_id
self.az2_lb_id = az2_lb_id
self.az3_lb_id = az3_lb_id
self.az1_innerlb_id = az1_innerlb_id
def all_to_az1(self):
"""
... ... @@ -45,19 +50,21 @@ class LBSwitch:
az1_nginxs = self.get_inventory_ifo("az1", 'java-nginx')
print "get all java nginx: %s for az: %s" % (az1_nginxs, "az1")
ip_weight_dict = {}
az1_nginx_weight = {}
for az1_nginx in az1_nginxs:
ip_weight_dict[az1_nginx] = 10
az1_nginx_weight[az1_nginx] = 10
# az2 公网流量切换到az1
ret_az2 = self.modify_alb_weight(lb_id=self.az2_lb_id, domain="*.yoho.cn", ip_weight_dict=ip_weight_dict)
ret_az2 = self.modify_alb_weight(lb_id=self.az2_lb_id, domain="*.yoho.cn", ip_weight_dict=az1_nginx_weight)
print("switch all incoming request from az2 to az1 result: %s" % ret_az2)
# 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)
# az1 公网流量、内部流量切换到az1
ret_az1 = self.modify_clb_weight(lb_id=self.az1_lb_id, ip_weight_dict=az1_nginx_weight)
ret_az1_inner = self.modify_alb_weight(lb_id=self.az1_innerlb_id, domain="*.yoho.yohoops.org",
ip_weight_dict=az1_nginx_weight)
print("switch all incoming request from az1 to az1 result: %s inner result: %s" % (ret_az1, ret_az1_inner))
return ret_az1 and ret_az2
return ret_az1 and ret_az1_inner and ret_az2
... ... @@ -67,17 +74,20 @@ class LBSwitch:
:return:
"""
az2_nginx = self.get_inventory_ifo("az2", 'java-nginx')
ip_weight_dict = {}
az2_nginx_weight = {}
for nginx in az2_nginx:
ip_weight_dict[nginx] = 10
az2_nginx_weight[nginx] = 10
ret_az2 = self.modify_alb_weight(lb_id=self.az2_lb_id, domain="*.yoho.cn", ip_weight_dict=ip_weight_dict)
# az2 公网流量切换到az2
ret_az2 = self.modify_alb_weight(lb_id=self.az2_lb_id, domain="*.yoho.cn", ip_weight_dict=az2_nginx_weight)
print("switch all incoming request from az2 to az2 result: %s" % ret_az2)
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 az2 result: %s" % ret_az1)
# az1 公网流量、内部流量切换到az2
ret_az1 = self.modify_clb_weight(lb_id=self.az1_lb_id, ip_weight_dict=az2_nginx_weight)
ret_az1_inner = self.modify_alb_weight(lb_id=self.az1_innerlb_id, domain="*.yoho.yohoops.org", ip_weight_dict=az2_nginx_weight)
print("switch all incoming request from az1 to az2 result: %s inner lb:%s" % (ret_az1, ret_az1_inner))
return ret_az1 & ret_az2
return ret_az1 and ret_az2 and ret_az1_inner
@staticmethod
def get_inventory_ifo(az, group):
... ... @@ -179,11 +189,13 @@ class LBSwitch:
return return_code.count(0) == len(return_code)
lbswitch = LBSwitch(secretId="AKID6dwpKadiQgbDpXDtyNhppIHPO5qPv5GK", secretKey="ACJkH9mg0DBA1PYpf0E7f3g534wBsQaW",
az1_lb_id="lb-e14oxiq3", az2_lb_id="lb-e14oxiq3", az3_lb_id="lb-e14oxiq3")
az1_lb_id="lb-dyh6eucn", az2_lb_id="lb-capto5b5", az3_lb_id="lb-capto5b5", az1_innerlb_id="lb-c26tgo5r")
#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.0.2": 10, "10.66.0.3": 10})
#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})
#ret = lbswitch.all_to_az1()
ret = lbswitch.all_to_az2()
print ret
... ...