<s> from oslo_log import log as logging <EOL> from nova . i18n import _LW <EOL> from nova . scheduler import filters <EOL> from nova . scheduler . filters import utils <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class BaseCoreFilter ( filters . BaseHostFilter ) : <EOL> def _get_cpu_allocation_ratio ( self , host_state , spec_obj ) : <EOL> raise NotImplementedError <EOL> def host_passes ( self , host_state , spec_obj ) : <EOL> """<STR_LIT>""" <EOL> if not host_state . vcpus_total : <EOL> LOG . warning ( _LW ( "<STR_LIT>" ) ) <EOL> return True <EOL> instance_vcpus = spec_obj . vcpus <EOL> cpu_allocation_ratio = self . _get_cpu_allocation_ratio ( host_state , <EOL> spec_obj ) <EOL> vcpus_total = host_state . vcpus_total * cpu_allocation_ratio <EOL> if vcpus_total > <NUM_LIT:0> : <EOL> host_state . limits [ '<STR_LIT>' ] = vcpus_total <EOL> if instance_vcpus > host_state . vcpus_total : <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> { '<STR_LIT>' : host_state , <EOL> '<STR_LIT>' : instance_vcpus , <EOL> '<STR_LIT>' : host_state . vcpus_total } ) <EOL> return False <EOL> free_vcpus = vcpus_total - host_state . vcpus_used <EOL> if free_vcpus < instance_vcpus : <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> { '<STR_LIT>' : host_state , <EOL> '<STR_LIT>' : instance_vcpus , <EOL> '<STR_LIT>' : free_vcpus } ) <EOL> return False <EOL> return True <EOL> class CoreFilter ( BaseCoreFilter ) : <EOL> """<STR_LIT>""" <EOL> def _get_cpu_allocation_ratio ( self , host_state , spec_obj ) : <EOL> return host_state . cpu_allocation_ratio <EOL> class AggregateCoreFilter ( BaseCoreFilter ) : <EOL> """<STR_LIT>""" <EOL> def _get_cpu_allocation_ratio ( self , host_state , spec_obj ) : <EOL> aggregate_vals = utils . aggregate_values_from_key ( <EOL> host_state , <EOL> '<STR_LIT>' ) <EOL> try : <EOL> ratio = utils . validate_num_values ( <EOL> aggregate_vals , host_state . cpu_allocation_ratio , cast_to = float ) <EOL> except ValueError as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" ) , e ) <EOL> ratio = host_state . cpu_allocation_ratio <EOL> return ratio </s>
