1
# Copyright (c) 2012 OpenStack, LLC.
2
# Copyright (c) 2012 Cloudscaling
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
9
# http://www.apache.org/licenses/LICENSE-2.0
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
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
24
LOG = logging.getLogger(__name__)
27
class AggregateInstanceExtraSpecsFilter(filters.BaseHostFilter):
28
"""AggregateInstanceExtraSpecsFilter works with InstanceType records."""
30
def host_passes(self, host_state, filter_properties):
31
"""Return a list of hosts that can create instance_type
33
Check that the extra specs associated with the instance type match
34
the metadata provided by aggregates. If not present return False.
36
instance_type = filter_properties.get('instance_type')
37
if 'extra_specs' not in instance_type:
40
context = filter_properties['context'].elevated()
41
metadata = db.aggregate_metadata_get_by_host(context, host_state.host)
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())