~justin-fathomdb/nova/schedule-compute-near-volume

« back to all changes in this revision

Viewing changes to nova/scheduler/constraint.py

  • Committer: Justin Santa Barbara
  • Date: 2011-03-07 20:27:59 UTC
  • Revision ID: justin@fathomdb.com-20110307202759-6y4on13t5td4zuz8
Initial implementation of proximity scheduler constraint

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    def datastore(self):
45
45
        return self.scheduler().datastore()
46
46
 
 
47
    def topology(self):
 
48
        context = self.request_context()
 
49
        return self.scheduler().topology(context)
 
50
 
47
51
    def selectivity(self):
48
52
        # We default to an intermediate value here
49
53
        return 0.75
85
89
                self.trace(_("skip %s: capacity") % host)
86
90
 
87
91
 
 
92
class InstanceConstraintPlaceNearLocation(SchedulerConstraint):
 
93
    def __init__(self, target_location):
 
94
        super(InstanceConstraintPlaceNearLocation, self).__init__()
 
95
        self.target_location = target_location
 
96
 
 
97
    def score_item(self, candidate):
 
98
        location = self.scheduler().get_service_location(candidate)
 
99
        distance = self.topology().distance(self.target_location, location)
 
100
        return 1 / (1 + distance) # Map to (0, 1]
 
101
 
 
102
    def get_candidate_iterator(self):
 
103
        """Returns an iterator over all items in best-to-least-good order"""
 
104
        topo = self.topology()
 
105
        for location in topo.find_by_distance_from(self.target_location):
 
106
            services = self.datastore().get_services_by_location(
 
107
                                                    self.request_context(), 
 
108
                                                    'compute',
 
109
                                                    location)
 
110
            for host in services:
 
111
                score = self.score_item(host)
 
112
                yield constraint_lib.Candidate(host.id, score)
 
113
 
 
114
    def selectivity(self):
 
115
        # TODO(justinsb): We need to systematize this a bit better...
 
116
        return 0.1 # We expect to be very selective
 
117
 
 
118
 
88
119
class VolumeConstraintFavorLeastGigabytes(SchedulerConstraint):
89
120
    def __init__(self):
90
121
        super(VolumeConstraintFavorLeastGigabytes, self).__init__()