#NEWLINE# def _numa_fit_instance_cell( host_cell , instance_cell , limit_cell = None ) : #NEWLINE# #INDENT# "Check if an instance cell can fit and set it's cell id\n\n    :param host_cell: host cell to fit the instance cell onto\n    :param instance_cell: instance cell we want to fit\n    :param limit_cell: an objects.NUMATopologyLimit or None\n\n    Make sure we can fit the instance cell onto a host cell and if so,\n    return a new objects.InstanceNUMACell with the id set to that of\n    the host, or None if the cell exceeds the limits of the host\n\n    :returns: a new instance cell or None\n    " #NEWLINE# if ( ( instance_cell . memory > host_cell . memory ) or ( len ( instance_cell . cpuset ) > len ( host_cell . cpuset ) ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if instance_cell . cpu_pinning_requested : #NEWLINE# #INDENT# new_instance_cell = _numa_fit_instance_cell_with_pinning ( host_cell , instance_cell ) #NEWLINE# if ( not new_instance_cell ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# new_instance_cell . pagesize = instance_cell . pagesize #NEWLINE# instance_cell = new_instance_cell #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if limit_cell : #NEWLINE# #INDENT# memory_usage = ( host_cell . memory_usage + instance_cell . memory ) #NEWLINE# cpu_usage = ( host_cell . cpu_usage + len ( instance_cell . cpuset ) ) #NEWLINE# cpu_limit = ( len ( host_cell . cpuset ) * limit_cell . cpu_allocation_ratio ) #NEWLINE# ram_limit = ( host_cell . memory * limit_cell . ram_allocation_ratio ) #NEWLINE# if ( ( memory_usage > ram_limit ) or ( cpu_usage > cpu_limit ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# pagesize = None #NEWLINE# if instance_cell . pagesize : #NEWLINE# #INDENT# pagesize = _numa_cell_supports_pagesize_request ( host_cell , instance_cell ) #NEWLINE# if ( not pagesize ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# instance_cell . id = host_cell . id #NEWLINE# instance_cell . pagesize = pagesize #NEWLINE# return instance_cell