def __init__(
     self,
     client,
 ):
     super(AliyunSlb, self).__init__()
     self.client = client
     self.request = DescribeLoadBalancersRequest()
     self.product = 'slb'
def __get_slb_id(slb_name, region):
    request = DescribeLoadBalancersRequest()
    request.set_RegionId(region)
    result = do_action(request, region)
    __slb_id = None
    for slb in result['LoadBalancers']['LoadBalancer']:
        if slb_name == slb['LoadBalancerName']:
            __slb_id = slb['LoadBalancerId']
    return __slb_id
Exemple #3
0
 def list_load_balancers(self, **params):
     load_balancers = []
     request = DescribeLoadBalancersRequest()
     request._params = params
     response = self._send_request(request)
     if response :
         load_balancers.extend(
             response.get("LoadBalancers", {}).get("LoadBalancer", [])
         )
     return load_balancers
Exemple #4
0
    def get_slbinstance_count(self, format, instance_id):
        from aliyunsdkslb.request.v20140515.DescribeLoadBalancersRequest import DescribeLoadBalancersRequest
        request = DescribeLoadBalancersRequest()

        request.set_accept_format(format)
        request.set_LoadBalancerId(instance_id)
        try:
            response = self.client.do_action_with_exception(request)
        except:
            return False
        return response
Exemple #5
0
    def get_slbinstance_id(self, format, page, limit):
        from aliyunsdkslb.request.v20140515.DescribeLoadBalancersRequest import DescribeLoadBalancersRequest
        request = DescribeLoadBalancersRequest()

        request.set_accept_format(format)
        request.set_PageNumber(page)
        request.set_PageSize(limit)
        try:
            response = self.client.do_action_with_exception(request)
        except:
            return False
        return response
Exemple #6
0
 def __init__(self, address, resultFormat=resultFormat):
     Aliyunsdk.__init__(self)
     self.resultFormat = resultFormat
     rel = GetSlbIpAll()
     rel.run()
     if address not in rel.iplist:
         print('IP:  %s is not exists' % address)
         os._exit(17)
     self.request = DescribeLoadBalancersRequest()
     self.request.set_accept_format(self.resultFormat)
     self.request.set_Address(address)
     self.slbid = ''
Exemple #7
0
 def refresh(self):
     request = DescribeLoadBalancersRequest()
     request.set_LoadBalancerId(self.load_balancer_id)
     items = _get_response(self._client, request, {},
                           'LoadBalancers.LoadBalancer')
     if not items:
         raise ClientException(
             errors.ERROR_INVALID_SERVER_RESPONSE,
             "Failed to find load balancer data from DescribeLoadBalancers "
             "response. "
             "LoadBalancerId = {0}".format(self.load_balancer_id))
     self._assign_attributes(items[0])
 def loadBalancingCreated(page_num=1):
     """
     查询所有SLB详细信息
     :param page_num:
     :return:
     """
     request = DescribeLoadBalancersRequest()
     request.set_accept_format('json')
     request.set_PageSize(page_num)
     request.set_PageSize(50)
     response = client().do_action_with_exception(request)
     response = json.loads(response)
     return response
Exemple #9
0
    def get_slbs(self, page_num=1, page_size=20):
        '''
        '''
        request = DescribeLoadBalancersRequest()
        request.set_accept_format('json')
        request.set_PageNumber(page_num)
        request.set_PageSize(page_size)

        data = self._request(request)
        total = data.get('TotalCount')
        data = data.get('LoadBalancers')
        data_list = data.get('LoadBalancer')
        data = {
            'total': total,
            'data_list': data_list,
        }
        return data
Exemple #10
0
 def slb(ecs_id):
     """
     查询所属ecs的负载均衡情况
     :param ecs_id: ecsid
     :return:
     """
     request = DescribeLoadBalancersRequest()
     request.set_accept_format('json')
     request.set_ServerId(ecs_id)
     response = client().do_action_with_exception(request)
     response = json.loads(response)
     if response.get('TotalCount') == 0:
         return {'slbId': None}
     slbListInfo = response.get('LoadBalancers')['LoadBalancer']
     if len(slbListInfo) > 1:
         slb_id = [i['LoadBalancerId'] for i in slbListInfo]
         return {'slbId': slb_id}
     return {'slbId': slbListInfo[0]['LoadBalancerId']}
Exemple #11
0
 def get_slb(self):
     """
     获取所有地域下slb负载均衡实例
     :return:
     """
     balancers = []
     regionids = self.DescribeRegions()
     try:
         for rid in regionids:
             client = AcsClient(self.AccessKeyId, self.AccessKeySecret, rid, connect_timeout=30)
             request = DescribeLoadBalancersRequest()
             request.set_accept_format('json')
             response = client.do_action_with_exception(request)
             # print(response)
             res = json.loads(str(response, encoding='utf-8'))
             balancers += res.get("LoadBalancers").get("LoadBalancer")
         return balancers
     except Exception as ex:
         print(ex)
Exemple #12
0
 def __init__(self, resultFormat=resultFormat):
     Aliyunsdk.__init__(self)
     self.resultFormat = resultFormat
     self.request = DescribeLoadBalancersRequest()
     self.request.set_accept_format(self.resultFormat)