<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 ExactRamConstraint ( 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> requested_ram = instance_type . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> if '<STR_LIT>' not in instance_type : <EOL> LOG . warn ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if requested_ram <= <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 requested_ram == hosts [ i ] . free_ram_mb : <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>' : requested_ram , <EOL> '<STR_LIT>' : hosts [ i ] . free_ram_mb } ) <EOL> return constraint_matrix </s>
