Commit bbf57926 authored by Antoine Millet's avatar Antoine Millet
Browse files

Implemented CPU reservation in allocator

parent c0e1517a
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -137,14 +137,19 @@ class HaveEnoughCPU(Filter):
    """

    DEFAULT_ALLOWED_RATIO = 1
    DEFAULT_RESERVED_CPU = 0

    def tql_filter(self, query):
        return '(%s)$cpualloc$cpu$cpuallowedratio$cpuremaining$cpuallocratio' % query
        return '(%s)$cpualloc$cpu$cpuallowedratio$cpuremaining$cpuallocratio$cpureserved' % query

    def filter(self, candidates):
        cpu = int(self.vmspec['cpu'])
        for candidate in candidates:
            ratio = (float(candidate.get('cpualloc')) + cpu) / float(candidate.get('cpu'))
            try:
                reserved = int(candidate.get('cpureserved', self.DEFAULT_RESERVED_CPU))
            except ValueError:
                reserved = self.DEFAULT_RESERVED_CPU
            ratio = (float(candidate.get('cpualloc')) + cpu) / (float(candidate.get('cpu')) + reserved)
            if ratio <= float(candidate.get('cpuallowedratio', self.DEFAULT_ALLOWED_RATIO)):
                yield candidate