def _parse_response(self, https_response):
        json_value = json.loads(https_response.read().decode("utf-8"))
        private_to_public_addresses = dict()
        for value in json_value:
            private_address = value[self._PRIVATE_ADDRESS_PROPERTY]
            public_address = value[self._PUBLIC_ADDRESS_PROPERTY]

            public_addr = AddressHelper.address_from_str(public_address)
            # If not explicitly given, create the private address with the public addresses port
            private_addr = AddressHelper.address_from_str(private_address, public_addr.port)
            private_to_public_addresses[private_addr] = public_addr

        return private_to_public_addresses
    def _validate_with_port(self, address, host, port):
        primaries, secondaries = AddressHelper.get_possible_addresses(address)
        self.assertEqual(1, len(primaries))
        self.assertEqual(0, len(secondaries))

        address = primaries[0]
        self.assertEqual(host, address.host)
        self.assertEqual(port, address.port)
    def _validate_without_port(self, address, host):
        primaries, secondaries = AddressHelper.get_possible_addresses(address)
        self.assertEqual(1, len(primaries))
        self.assertEqual(self.default_port_count - 1, len(secondaries))

        for i in range(self.default_port_count):
            if i == 0:
                address = primaries[i]
            else:
                address = secondaries[i - 1]
            self.assertEqual(host, address.host)
            self.assertEqual(self.default_port + i, address.port)
Example #4
0
    def load_addresses(self):
        """Returns the possible primary and secondary member addresses to connect to."""
        configured_addresses = self._addresses

        if not configured_addresses:
            configured_addresses = ["127.0.0.1"]

        primaries = []
        secondaries = []
        for address in configured_addresses:
            p, s = AddressHelper.get_possible_addresses(address)
            primaries.extend(p)
            secondaries.extend(s)

        return primaries, secondaries