标签:set lb request json ecs import response
修改lb权重,通知钉钉
前提需要安装阿里的核心库
#!/usr/local/python-3.6.4/bin/python3 #coding=utf-8 from aliyunsdkcore.client import AcsClient from aliyunsdkcore.acs_exception.exceptions import ClientException from aliyunsdkcore.acs_exception.exceptions import ServerException from aliyunsdkslb.request.v20140515.SetBackendServersRequest import SetBackendServersRequest from urllib import request as ddrequest import json from sys import argv client = AcsClient('LTAI42e74K2hrtmu', 'f4S7rx9KEFv9Js3AR5KmU6V7g9D4xd', 'cn-beijing') access_token = "dingding" def set_lb(request,ecs,weight,loadslb): serverid = ecs.get("serverid") request.set_accept_format('json') slb_list = '[{"ServerId":"%s","Weight":"%s"},]' % (str(serverid),str(weight)) print(slb_list) request.set_BackendServers(slb_list) request.set_LoadBalancerId(loadslb) try: response = client.do_action_with_exception(request) except Exception as e: response = {"hostname":ecs.get("hostname"),"ip":ecs.get("ip"),"message":"在修改权重为100的时候,发生了意外"} send_msg(response) else: response = {"hostname":ecs.get("hostname"),"ip":ecs.get("ip"),"message":"修改权重为100成功"} send_msg(response) def send_msg(response): url = "https://oapi.dingtalk.com/robot/send?access_token=" + access_token data = { "msgtype": "text", "text": { "content": response }, "at": { "isAtAll": "false" } } json_data= json.dumps(data).encode(encoding='utf-8') print(json_data) header_encoding = {"Content-Type": "application/json"} req = ddrequest.Request(url=url, data=json_data, headers=header_encoding) res = ddrequest.urlopen(req) res = res.read() print(res.decode(encoding='utf-8')) if __name__ == "__main__": request = SetBackendServersRequest() ecs = {"hostname":"pc-prod-1","ip":"ip","serverid":"id"} weight = "100" loadslb = "lb-id" set_lb(request,ecs,weight,loadslb)
标签:set,lb,request,json,ecs,import,response 来源: https://www.cnblogs.com/jokerbj/p/11101935.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。