Пример #1
0
def create_tcp_listener(params):
    '''
    create_tcp_listener:创建tcp监听
    官网API参考链接: https://help.aliyun.com/document_detail/27594.html
    '''
    counter = 0
    while counter < TRY_TIME:
        try:
            request = CreateLoadBalancerTCPListenerRequest.CreateLoadBalancerTCPListenerRequest(
            )
            #负载均衡实例的ID
            request.set_LoadBalancerId(params["load_balancer_id"])
            #监听的带宽峰值
            request.set_Bandwidth(params["bandwidth"])
            #负载均衡实例前端使用的端口
            request.set_ListenerPort(params["listener_port"])
            #负载均衡实例后端使用的端口
            request.set_BackendServerPort(params["backend_server_port"])
            response = client.do_action_with_exception(request)

            response_json = json.loads(response)
            return response_json
        except ServerException as e:
            if ExceptionHandler.server_exception(e):
                return e
        except ClientException as e:
            if ExceptionHandler.client_exception(e):
                return e
        finally:
            counter += 1
Пример #2
0
 def add_lb_tcplister(self, loadbalanceid, listenerport, vservergroup):
     try:
         # 设置参数
         request = CreateLoadBalancerTCPListenerRequest.CreateLoadBalancerTCPListenerRequest()
         request.set_accept_format('json')
         request.add_query_param('LoadBalancerId', loadbalanceid)
         request.add_query_param('ListenerPort', listenerport)
         request.add_query_param('Bandwidth', -1)
         request.add_query_param('RegionId', self.instance_regionid)
         request.add_query_param('VServerGroupId', vservergroup)
         # 发起请求
         response = self.cli.do_action_with_exception(request)
         return response.decode('utf8')
     except Exception as ee:
         log.error('创建监听错误{}:'.format(ee))
Пример #3
0
def slbaddtcplisten():
    request = CreateLoadBalancerTCPListenerRequest.CreateLoadBalancerTCPListenerRequest(
    )
    request.set_accept_format('json')
    # SLB的地域和ID号
    request.add_query_param('RegionId', 'cn-hangzhou')
    request.add_query_param('Bandwidth', 5000)
    request.add_query_param('LoadBalancerId', SLBid)
    request.add_query_param('ListenerPort', Fport)
    request.add_query_param('BackendServerPort', Bport)
    request.add_query_param('Scheduler', 'wlc')
    request.add_query_param('HealthCheckType', 'tcp')
    request.add_query_param('HealthCheckConnectPort', Bport)
    # 发起请求
    response = clt.do_action(request)
    print response