示例#1
0
 def testBackendsNotEqual(self):
     bs1 = BackendServer('id1', 1)
     bs2 = BackendServer('id2', 1)
     bs3 = BackendServer('id3', 1)
     bs4 = BackendServer('id4', 1)
     ls1 = ListenerStatus(1, [bs1, bs2])
     ls2 = ListenerStatus(1, [bs3, bs4])
     self.assertNotEqual(ls1, ls2)
示例#2
0
    def add_backend_server_ids(self, load_balancer_id, backend_server_ids):
        """Helper wrapper to add backend server IDs specified to the SLB
           specified.

        Args:
            load_balancer_id (str): Aliyun SLB LoadBalancerId to retrieve.
            backend_server_ids (list of str): the backend server ids to add
        """
        backends = [BackendServer(bsid, None) for bsid in backend_server_ids]
        return self.add_backend_servers(load_balancer_id, backends)
示例#3
0
    def get_load_balancer(self, load_balancer_id):
        """Get a LoadBalancer by ID.

        Args:
            load_balancer_id (str): Aliyun SLB LoadBalancerId to retrieve.

        Returns:
            LoadBalancer with given ID.
        """
        resp = self.get({
            'Action': 'DescribeLoadBalancerAttribute',
            'LoadBalancerId': load_balancer_id
        })

        backend_servers = []
        for bs in resp['BackendServers']['BackendServer']:
            backend_servers.append(BackendServer(bs['ServerId'], bs['Weight']))

        return LoadBalancer(
            resp['LoadBalancerId'], resp['RegionId'], resp['LoadBalancerName'],
            resp['LoadBalancerStatus'], resp['Address'], resp['AddressType'],
            [port for port in resp['ListenerPorts']['ListenerPort']],
            backend_servers)
示例#4
0
 def testEqual(self):
     bs1 = BackendServer('id', 1)
     bs2 = BackendServer('id', 1)
     self.assertEqual(bs1, bs2)
示例#5
0
 def testPortNotEqual(self):
     bs1 = BackendServer('id1', 1)
     bs2 = BackendServer('id2', 1)
     ls1 = ListenerStatus(1, [bs1, bs2])
     ls2 = ListenerStatus(2, [bs1, bs2])
     self.assertNotEqual(ls1, ls2)
示例#6
0
 def testRepr(self):
     bs = BackendServer('id', 1)
     self.assertTrue(repr(bs).startswith(u'<BackendServer id'))