1
# Copyright (c) 2012 Intel
2
# Copyright (c) 2012 OpenStack, LLC.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
21
from cinder.openstack.common import log as logging
22
from cinder.openstack.common.scheduler import filters
25
LOG = logging.getLogger(__name__)
28
class CapacityFilter(filters.BaseHostFilter):
29
"""CapacityFilter filters based on volume host's capacity utilization."""
31
def host_passes(self, host_state, filter_properties):
32
"""Return True if host has sufficient capacity."""
33
volume_size = filter_properties.get('size')
35
if not host_state.free_capacity_gb:
37
LOG.warning(_("Free capacity not set;"
38
"volume node info collection broken."))
41
reserved = float(host_state.reserved_percentage) / 100
42
free = math.floor(host_state.free_capacity_gb * (1 - reserved))
44
return free >= volume_size