@@ -195,27 +195,24 @@ There are many standard filter classes which may be used
195
195
* |NUMATopologyFilter | - filters hosts based on the NUMA topology requested by the
196
196
instance, if any.
197
197
198
- Now we can focus on these standard filter classes in some detail. We'll skip the
199
- simplest ones, such as |AllHostsFilter |, |CoreFilter | and |RamFilter |,
200
- because their functionality is relatively simple and can be understood from the
201
- code. For example class |RamFilter | has the next realization:
198
+ Now we can focus on these standard filter classes in some detail. Some filters
199
+ such as |AllHostsFilter | and |NumInstancesFilter | are relatively simple and can be
200
+ understood from the code. For example, |NumInstancesFilter | has the following implementation::
202
201
203
- ::
202
+ class NumInstancesFilter(filters.BaseHostFilter):
203
+ """Filter out hosts with too many instances."""
204
204
205
- class RamFilter(filters.BaseHostFilter ):
206
- """Ram Filter with over subscription flag"""
205
+ def _get_max_instances_per_host(self, host_state, spec_obj ):
206
+ return CONF.filter_scheduler.max_instances_per_host
207
207
208
- def host_passes(self, host_state, filter_properties):
209
- """Only return hosts with sufficient available RAM."""
210
- instance_type = filter_properties.get('instance_type')
211
- requested_ram = instance_type['memory_mb']
212
- free_ram_mb = host_state.free_ram_mb
213
- total_usable_ram_mb = host_state.total_usable_ram_mb
214
- used_ram_mb = total_usable_ram_mb - free_ram_mb
215
- return total_usable_ram_mb * FLAGS.ram_allocation_ratio - used_ram_mb >= requested_ram
208
+ def host_passes(self, host_state, spec_obj):
209
+ num_instances = host_state.num_instances
210
+ max_instances = self._get_max_instances_per_host(host_state, spec_obj)
211
+ passes = num_instances < max_instances
212
+ return passes
216
213
217
- Here :oslo.config:option: `ram_allocation_ratio ` means the virtual RAM to physical
218
- RAM allocation ratio (it is `` 1.5 `` by default) .
214
+ Here :oslo.config:option: `filter_scheduler.max_instances_per_host ` means the
215
+ maximum number of instances that be active on a host .
219
216
220
217
The |AvailabilityZoneFilter | looks at the availability zone of compute node
221
218
and availability zone from the properties of the request. Each compute service
0 commit comments