Esempio n. 1
0
def get_servers_for(node: Optional[Node]) -> FrozenSet[str]:
    """Return NTP servers to use for the given node."""
    if node is None or node.is_region_controller or _ntp_external_only():
        routable_addrs = _get_external_servers()
    elif node.is_rack_controller:
        # Point the rack back at all the region controllers.
        regions = RegionController.objects.all()
        routable_addrs_map = get_routable_address_map(regions, node)
        routable_addrs = reduce_routable_address_map(routable_addrs_map)
    elif node.is_machine:
        # Point the node back to its primary and secondary rack controllers as
        # a source of time information.
        racks = node.get_boot_rack_controllers()
        if len(racks) == 0:
            # This machine hasn't previously booted, so use all racks. Perhaps
            # we should do this anyway, and disregard boot rack information?
            racks = RackController.objects.all()
        routable_addrs_map = get_routable_address_map(racks, node)
        routable_addrs = reduce_routable_address_map(routable_addrs_map)
    else:
        # Point the node back at *all* rack controllers.
        racks = RackController.objects.all()
        routable_addrs_map = get_routable_address_map(racks, node)
        routable_addrs = reduce_routable_address_map(routable_addrs_map)
    # Return a frozenset of strings, be they IP addresses or hostnames.
    return frozenset(map(str, routable_addrs))
Esempio n. 2
0
 def _getPeers(self, region):
     """Return syslog peers to use for the given region."""
     peer_regions = RegionController.objects.exclude(id=region.id)
     peer_addresses_map = get_routable_address_map(peer_regions, region)
     return frozenset(
         (other_region.hostname, sorted(ip_addresses)[0])
         for other_region, ip_addresses in peer_addresses_map.items())
Esempio n. 3
0
def get_peers_for(node: Node) -> FrozenSet[str]:
    """Return NTP peers to use for the given node.

    For all node types other than region or region+rack controllers, this
    returns the empty set.
    """
    if node is None:
        return frozenset()
    elif node.is_region_controller:
        peer_regions = RegionController.objects.exclude(id=node.id)
        peer_addresses_map = get_routable_address_map(peer_regions, node)
        peer_addresses = reduce_routable_address_map(peer_addresses_map)
        return frozenset(map(str, peer_addresses))
    else:
        return frozenset()