summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Gordon <jogo@cloudscaling.com>2012-01-19 22:18:09 -0800
committerJoe Gordon <jogo@cloudscaling.com>2012-01-20 14:52:14 -0800
commit7b94f660f41b03d175ae5e89b6dffc69550443d2 (patch)
treea92633ee58213721a00f688f444e029319c2844f
parentfd1aa4613b9a644ad2d702ac2d15cf12cef589c5 (diff)
downloadnova-7b94f660f41b03d175ae5e89b6dffc69550443d2.tar.gz
nova-7b94f660f41b03d175ae5e89b6dffc69550443d2.tar.xz
nova-7b94f660f41b03d175ae5e89b6dffc69550443d2.zip
Pull out ram_filter into a separate filter
Change-Id: Id38bbd0e8dbcd00fee836d555005b954973ae90c
-rw-r--r--nova/scheduler/filters/__init__.py1
-rw-r--r--nova/scheduler/filters/compute_filter.py8
-rw-r--r--nova/scheduler/filters/ram_filter.py36
-rw-r--r--nova/scheduler/host_manager.py2
-rw-r--r--nova/tests/scheduler/test_host_filters.py4
5 files changed, 40 insertions, 11 deletions
diff --git a/nova/scheduler/filters/__init__.py b/nova/scheduler/filters/__init__.py
index f9bf6641b..4a035971c 100644
--- a/nova/scheduler/filters/__init__.py
+++ b/nova/scheduler/filters/__init__.py
@@ -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
diff --git a/nova/scheduler/filters/compute_filter.py b/nova/scheduler/filters/compute_filter.py
index 3eb2f6f73..f576eace1 100644
--- a/nova/scheduler/filters/compute_filter.py
+++ b/nova/scheduler/filters/compute_filter.py
@@ -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):
diff --git a/nova/scheduler/filters/ram_filter.py b/nova/scheduler/filters/ram_filter.py
new file mode 100644
index 000000000..832a2588a
--- /dev/null
+++ b/nova/scheduler/filters/ram_filter.py
@@ -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
diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py
index 6996155ff..c77145fa6 100644
--- a/nova/scheduler/host_manager.py
+++ b/nova/scheduler/host_manager.py
@@ -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.')
diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py
index 8462422ad..52c3b10dc 100644
--- a/nova/tests/scheduler/test_host_filters.py
+++ b/nova/tests/scheduler/test_host_filters.py
@@ -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}