~ubuntu-branches/ubuntu/precise/nova/precise-updates

« back to all changes in this revision

Viewing changes to nova/scheduler/filters/affinity_filter.py

  • Committer: Package Import Robot
  • Author(s): Steve Beattie
  • Date: 2012-07-05 10:58:26 UTC
  • mfrom: (80.1.2 precise-security)
  • Revision ID: package-import@ubuntu.com-20120705105826-gsi70c5cywt8vw1y
Tags: 2012.1+stable~20120612-3ee026e-0ubuntu1.2
* SECURITY UPDATE: scheduler affinity denial of service
  - debian/patches/CVE-2012-3371.patch: lookup instance ids only once
    instead of once for each scheduler hint instance id.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    def __init__(self):
27
27
        self.compute_api = compute.API()
28
28
 
29
 
    def _affinity_host(self, context, instance_id):
30
 
        return self.compute_api.get(context, instance_id)['host']
 
29
    def _all_hosts(self, context):
 
30
        all_hosts = {}
 
31
        for instance in self.compute_api.get_all(context):
 
32
            all_hosts[instance['uuid']] = instance['host']
 
33
        return all_hosts
31
34
 
32
35
 
33
36
class DifferentHostFilter(AffinityFilter):
38
41
        scheduler_hints = filter_properties['scheduler_hints']
39
42
        me = host_state.host
40
43
 
 
44
        all_hosts = self._all_hosts(context)
41
45
        affinity_uuids = scheduler_hints.get('different_host', [])
42
46
        if affinity_uuids:
43
 
            return not any([i for i
44
 
                              in affinity_uuids
45
 
                              if self._affinity_host(context, i) == me])
 
47
            return not any([i for i in affinity_uuids
 
48
                              if all_hosts.get(i) == me])
46
49
        # With no different_host key
47
50
        return True
48
51
 
57
60
        scheduler_hints = filter_properties['scheduler_hints']
58
61
        me = host_state.host
59
62
 
 
63
        all_hosts = self._all_hosts(context)
60
64
        affinity_uuids = scheduler_hints.get('same_host', [])
61
65
        if affinity_uuids:
62
 
            return any([i for i
63
 
                          in affinity_uuids
64
 
                          if self._affinity_host(context, i) == me])
 
66
            return any([i for i in affinity_uuids
 
67
                          if all_hosts.get(i) == me])
65
68
        # With no same_host key
66
69
        return True
67
70