<s> from oslo_log import log as logging <EOL> from nova . i18n import _LW <EOL> from nova_solverscheduler . scheduler . solvers import constraints <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class ExactVcpuConstraint ( constraints . BaseLinearConstraint ) : <EOL> """<STR_LIT>""" <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> instance_type = filter_properties . get ( '<STR_LIT>' ) or { } <EOL> if not instance_type : <EOL> return constraint_matrix <EOL> else : <EOL> instance_vcpus = instance_type [ '<STR_LIT>' ] <EOL> if instance_vcpus <= <NUM_LIT:0> : <EOL> LOG . warn ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> return constraint_matrix <EOL> for i in xrange ( num_hosts ) : <EOL> if not hosts [ i ] . vcpus_total : <EOL> LOG . warn ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , { '<STR_LIT:host>' : hosts [ i ] } ) <EOL> constraint_matrix [ i ] = [ False for j in xrange ( num_instances ) ] <EOL> continue <EOL> else : <EOL> usable_vcpus = hosts [ i ] . vcpus_total - hosts [ i ] . vcpus_used <EOL> if instance_vcpus == usable_vcpus : <EOL> constraint_matrix [ i ] = ( <EOL> [ True ] + [ False for j in xrange ( num_instances - <NUM_LIT:1> ) ] ) <EOL> else : <EOL> constraint_matrix [ i ] = [ False for j in xrange ( num_instances ) ] <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> { '<STR_LIT:host>' : hosts [ i ] , <EOL> '<STR_LIT>' : instance_vcpus , <EOL> '<STR_LIT>' : usable_vcpus } ) <EOL> return constraint_matrix </s>
