"""
Returns all mirrors in random order with preferred mirrors first
"""
- # Lookup the client
- network = self.location.lookup("%s" % address)
-
def __sort(mirror):
# Generate some random value for each mirror
r = random.random()
# Add the preference score
- if network:
- r += mirror.is_preferred_for_network(network)
+ r += mirror.is_preferred_for_address(address)
return r
def is_preferred_for_address(self, address):
"""
- Check if this mirror is preferred for this address
+ Returns a score of how much the mirror is preferred for this address
"""
# Lookup the client
network = self.backend.mirrors.location.lookup("%s" % address)
- # Check for the entire network
- return self.is_preferred_for_network(network)
+ # Return if we could not find the client
+ if not network:
+ return 0
- def is_preferred_for_network(self, network):
- """
- Returns a score of how much the mirror is preferred for this network.
- """
first_address = ipaddress.ip_address(network.first_address)
last_address = ipaddress.ip_address(network.last_address)