~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/scheduler/filters/capacity_filter.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2012 Intel
 
2
# Copyright (c) 2012 OpenStack, LLC.
 
3
#
 
4
# All Rights Reserved.
 
5
#
 
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
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
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
 
16
#    under the License.
 
17
 
 
18
 
 
19
import math
 
20
 
 
21
from cinder.openstack.common import log as logging
 
22
from cinder.openstack.common.scheduler import filters
 
23
 
 
24
 
 
25
LOG = logging.getLogger(__name__)
 
26
 
 
27
 
 
28
class CapacityFilter(filters.BaseHostFilter):
 
29
    """CapacityFilter filters based on volume host's capacity utilization."""
 
30
 
 
31
    def host_passes(self, host_state, filter_properties):
 
32
        """Return True if host has sufficient capacity."""
 
33
        volume_size = filter_properties.get('size')
 
34
 
 
35
        if not host_state.free_capacity_gb:
 
36
            # Fail Safe
 
37
            LOG.warning(_("Free capacity not set;"
 
38
                          "volume node info collection broken."))
 
39
            return False
 
40
 
 
41
        reserved = float(host_state.reserved_percentage) / 100
 
42
        free = math.floor(host_state.free_capacity_gb * (1 - reserved))
 
43
 
 
44
        return free >= volume_size