set_lb
修改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的更多相关文章
随机推荐
- GO 解决使用bee工具,报 bash: bee: command not found
我最近使用beego时,遇到以下问题:command not found使用vscode时,运行bee run,报以下错 我查到一篇文章csdn,说用拷贝bee.exe方法,我觉得纯扯淡 如何解决? ...
- axios post方式请求x-ww格式的数据
//使用axios时,要确定是json格式还是x-www格式的,axios默认是json格式的,如果是x-ww格式需要做如下配置: let url = "/hehe/site/getcomm ...
- Flask常用实列化参数
Flask中实列化配置: app = Flask( __name__, template_folder=’temp’ , ...... ) >template_folder = "te ...
- chentos7 编译安装keepalived 1.4.5
准备工作: 下载源码包,官方网站 下载命令:wget https://www.keepalived.org/software/keepalived-1.4.5.tar.gz 解压tar包,命令: ta ...
- ##ant 打包apk
ant 打包apk 1. 参考: Android Ant 批量多渠道打包实例 单个渠道类似操作,只不过不用修改build.xml文件 2. 修改ant debug的包签名,使用和release版本相同 ...
- terminal使用kubectl.exe delete pod podname删不掉
今天通过kubernetes的dashboard进行删除有问题或者重启次数太多的pod,发现删不掉,然后就在本地尝试使用terminal进行删除 先获取指定namespace下的所有的pod,根据st ...
- sizeof 计算 struct 占字节数的方法总结
矛盾焦点: 1.结构体的内存对齐方式 字节对齐的目的: 1.提高CPU存储变量的速度 计算的核心点(默认对齐方式): 1.结构体内的每一个成员的起始地址跟结构体起始地址的偏移量要刚好是自己字节数的整数 ...
- [BZOJ2186]沙拉公主的困惑
[BZOJ2186]沙拉公主的困惑 题面 大富翁国因为通货膨胀,以及假钞泛滥,政府决定推出一项新的政策:现有钞票编号范围为1到N的阶乘,但是,政府只发行编号与M!互质的钞票.房地产第一大户沙拉公主决定 ...
- Spring Cloud @RefreshScope 原理是什么?
要清楚RefreshScope,先要了解Scope Scope(org.springframework.beans.factory.config.Scope)是Spring 2.0开始就有的核心的概念 ...
- Executor多线程框架
啥都别说了,上代码: import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; impor ...