~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2012 OpenStack, LLC.
 
2
# Copyright (c) 2012 Cloudscaling
 
3
# All Rights Reserved.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
#    Unless required by applicable law or agreed to in writing, software
 
12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
from nova import db
 
18
from nova import exception
 
19
from nova.openstack.common import log as logging
 
20
from nova.scheduler import filters
 
21
from nova import utils
 
22
 
 
23
 
 
24
LOG = logging.getLogger(__name__)
 
25
 
 
26
 
 
27
class AggregateInstanceExtraSpecsFilter(filters.BaseHostFilter):
 
28
    """AggregateInstanceExtraSpecsFilter works with InstanceType records."""
 
29
 
 
30
    def host_passes(self, host_state, filter_properties):
 
31
        """Return a list of hosts that can create instance_type
 
32
 
 
33
        Check that the extra specs associated with the instance type match
 
34
        the metadata provided by aggregates.  If not present return False.
 
35
        """
 
36
        instance_type = filter_properties.get('instance_type')
 
37
        if 'extra_specs' not in instance_type:
 
38
            return True
 
39
 
 
40
        context = filter_properties['context'].elevated()
 
41
        metadata = db.aggregate_metadata_get_by_host(context, host_state.host)
 
42
 
 
43
        for key, value in instance_type['extra_specs'].iteritems():
 
44
            aggregate_value = metadata.get(key, None)
 
45
            if not aggregate_value or value not in aggregate_value:
 
46
                LOG.debug(_("%(host_state)s fails "
 
47
                        "AggregateInstanceExtraSpecsFilter requirements, "
 
48
                        "missing %(key)s,'%(value)s'="
 
49
                        "'%(aggregate_value)s'"), locals())
 
50
                return False
 
51
        return True