<s> import copy <EOL> from oslo_log import log as logging <EOL> from nova . scheduler . filters import numa_topology_filter <EOL> from nova_solverscheduler . scheduler . solvers import constraints <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class NUMATopologyConstraint ( constraints . BaseLinearConstraint ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( NUMATopologyConstraint , self ) . __init__ ( ) <EOL> self . host_filter = numa_topology_filter . NUMATopologyFilter ( ) <EOL> def _get_acceptable_instance_num ( self , host_state , filter_properties , <EOL> max_num ) : <EOL> instance = filter_properties [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> acceptable_num = <NUM_LIT:0> <EOL> while acceptable_num < max_num : <EOL> if self . host_filter . host_passes ( host_state , filter_properties ) : <EOL> acceptable_num += <NUM_LIT:1> <EOL> host_state . consume_from_instance ( instance ) <EOL> else : <EOL> break <EOL> return acceptable_num <EOL> def get_constraint_matrix ( self , hosts , filter_properties ) : <EOL> num_hosts = len ( hosts ) <EOL> num_instances = filter_properties . get ( '<STR_LIT>' ) <EOL> constraint_matrix = [ [ True for j in xrange ( num_instances ) ] <EOL> for i in xrange ( num_hosts ) ] <EOL> for i in xrange ( num_hosts ) : <EOL> host_state = copy . deepcopy ( hosts [ i ] ) <EOL> acceptable_instance_num = self . _get_acceptable_instance_num ( <EOL> host_state , filter_properties , num_instances ) <EOL> if acceptable_instance_num < num_instances : <EOL> inacceptable_num = num_instances - acceptable_instance_num <EOL> constraint_matrix [ i ] = ( <EOL> [ True for j in xrange ( acceptable_instance_num ) ] + <EOL> [ False for j in xrange ( inacceptable_num ) ] ) <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> { '<STR_LIT:host>' : hosts [ i ] , <EOL> '<STR_LIT>' : acceptable_instance_num } ) <EOL> numa_topology_limit = host_state . limits . get ( '<STR_LIT>' ) <EOL> if numa_topology_limit : <EOL> hosts [ i ] . limits [ '<STR_LIT>' ] = numa_topology_limit <EOL> return constraint_matrix </s>
