def get_backend_servers(self, load_balancer_id, listener_port=None): """Get backend servers for a given load balancer and its listener port. If listener_port is not specified, all listeners are listed separately. Args: load_balancer_id (str): Aliyun SLB LoadBalancerId to retrieve. listener_port (int, optional): the port to get backend server statuses for Returns: List of ListenerStatus """ params = { 'Action': 'DescribeBackendServers', 'LoadBalancerId': load_balancer_id, } if listener_port is not None: params['ListenerPort'] = listener_port listeners = [] resp = self.get(params) for listener in resp['Listeners']['Listener']: backends = [] for bs in listener['BackendServers']['BackendServer']: backends.append( BackendServerStatus(bs['ServerId'], bs['ServerHealthStatus'])) listeners.append(ListenerStatus(listener['ListenerPort'], backends)) return listeners
def testRepr(self): bss = BackendServerStatus('id', 's') self.assertTrue( repr(bss).startswith(u'<BackendServerStatus id is s at '))
def testNotEqual(self): bss1 = BackendServerStatus('id1', 's') bss2 = BackendServerStatus('id2', 's') self.assertNotEqual(bss1, bss2)