Pull out ram_filter into a separate filter

Change-Id: Id38bbd0e8dbcd00fee836d555005b954973ae90c
This commit is contained in:
Joe Gordon
2012-01-19 22:18:09 -08:00
parent 20f35eccfb
commit d75602495c
5 changed files with 40 additions and 11 deletions

View File

@@ -34,3 +34,4 @@ from abstract_filter import AbstractHostFilter
from all_hosts_filter import AllHostsFilter
from compute_filter import ComputeFilter
from json_filter import JsonFilter
from ram_filter import RamFilter

View File

@@ -38,12 +38,6 @@ class ComputeFilter(abstract_filter.AbstractHostFilter):
return False
return True
def _basic_ram_filter(self, host_state, instance_type):
"""Only return hosts with sufficient available RAM."""
requested_ram = instance_type['memory_mb']
free_ram_mb = host_state.free_ram_mb
return free_ram_mb >= requested_ram
def host_passes(self, host_state, filter_properties):
"""Return a list of hosts that can create instance_type."""
instance_type = filter_properties.get('instance_type')
@@ -54,8 +48,6 @@ class ComputeFilter(abstract_filter.AbstractHostFilter):
if not utils.service_is_up(service) or service['disabled']:
return False
if not self._basic_ram_filter(host_state, instance_type):
return False
if not capabilities.get("enabled", True):
return False
if not self._satisfies_extra_specs(capabilities, instance_type):

View File

@@ -0,0 +1,36 @@
# Copyright (c) 2011 Openstack, LLC.
# Copyright (c) 2012 Cloudscaling
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova import flags
from nova import log as logging
from nova.scheduler.filters import abstract_filter
LOG = logging.getLogger('nova.scheduler.filter.ram_filter')
FLAGS = flags.FLAGS
flags.DEFINE_float("ram_allocation_ratio", 1.0,
"virtual ram to physical ram allocation ratio")
class RamFilter(abstract_filter.AbstractHostFilter):
"""Ram Filter with over subscription flag"""
def host_passes(self, host_state, filter_properties):
"""Only return hosts with sufficient available RAM."""
instance_type = filter_properties.get('instance_type')
requested_ram = instance_type['memory_mb']
free_ram_mb = host_state.free_ram_mb
return free_ram_mb * FLAGS.ram_allocation_ratio >= requested_ram

View File

@@ -32,7 +32,7 @@ flags.DEFINE_integer('reserved_host_disk_mb', 0,
'Amount of disk in MB to reserve for host/dom0')
flags.DEFINE_integer('reserved_host_memory_mb', 512,
'Amount of memory in MB to reserve for host/dom0')
flags.DEFINE_list('default_host_filters', ['ComputeFilter'],
flags.DEFINE_list('default_host_filters', ['RamFilter', 'ComputeFilter'],
'Which filters to use for filtering hosts when not specified '
'in the request.')

View File

@@ -53,9 +53,9 @@ class HostFiltersTestCase(test.TestCase):
'service': service})
self.assertTrue(filt_cls.host_passes(host, filter_properties))
def test_compute_filter_fails_on_memory(self):
def test_ram_filter_fails_on_memory(self):
self._stub_service_is_up(True)
filt_cls = filters.ComputeFilter()
filt_cls = filters.RamFilter()
filter_properties = {'instance_type': {'memory_mb': 1024}}
capabilities = {'enabled': True}
service = {'disabled': False}