'Makes room for a volume cache entry.
Returns True if successful, false otherwise.'

def ensure_space(self, context, volume):

    if ((self.max_cache_size_gb == 0) and (self.max_cache_size_count == 0)):
        return True
    if ((self.max_cache_size_gb != 0) and (volume.size > self.max_cache_size_gb)):
        return False
    entries = self.db.image_volume_cache_get_all(context, **self._get_query_filters(volume))
    current_count = len(entries)
    current_size = 0
    for entry in entries:
        current_size += entry['size']
    current_size += volume.size
    current_count += 1
    LOG.debug('Image-volume    cache    for    %(service)s    current_size    (GB)    =    %(size_gb)s    (max    =    %(max_gb)s),    current    count    =    %(count)s    (max    =    %(max_count)s).', {'service': volume.service_topic_queue, 'size_gb': current_size, 'max_gb': self.max_cache_size_gb, 'count': current_count, 'max_count': self.max_cache_size_count})
    while (((current_size > self.max_cache_size_gb) or (current_count > self.max_cache_size_count)) and len(entries)):
        entry = entries.pop()
        LOG.debug('Reclaiming    image-volume    cache    space;    removing    cache    entry    %(entry)s.', {'entry': self._entry_to_str(entry)})
        self._delete_image_volume(context, entry)
        current_size -= entry['size']
        current_count -= 1
        LOG.debug('Image-volume    cache    for    %(service)s    new    size    (GB)    =    %(size_gb)s,    new    count    =    %(count)s.', {'service': volume.service_topic_queue, 'size_gb': current_size, 'count': current_count})
    if (self.max_cache_size_gb > 0):
        if (current_size > self.max_cache_size_gb > 0):
            LOG.warning('Image-volume    cache    for    %(service)s    does    not    have    enough    space    (GB).', {'service': volume.service_topic_queue})
            return False
    return True
