一、配置好RAM账号的权限(SLB管理权限)
二、安装依赖
pip3 install aliyun-python-sdk-slb
pip3 install aliyun-python-sdk-core-v3
三、daemon
from aliyunsdkcore import client
from aliyunsdkslb.request.v20140515 import SetBackendServersRequest
import os AccessKeyId = 'xxx' #AccessKeyID
AccessKeySecret = 'xxx' #AccessKeySecret
Endpoint = 'cn-qingdao' #地区 client = client.AcsClient(AccessKeyId,AccessKeySecret,Endpoint)
#ecs实例
ecsA = "xxxxx" #ecs实例id
#权重
ecsA_weight = "90"
req_parm1 = "BackendServers"
req_parm2 = [{"ServerId": ecsA, "Weight": ecsA_weight}] request = SetBackendServersRequest.SetBackendServersRequest()
request.set_accept_format('json')
request.add_query_param('LoadBalancerId','#负载均衡ID')
request.add_query_param(req_parm1,req_parm2)
response = client.do_action_with_exception(request) print (response) # 打印返回