'Return True if host has sufficient capacity.'

def backend_passes(self, backend_state, filter_properties):

    volid = None
    if (backend_state.backend_id == filter_properties.get('vol_exists_on')):
        return True
    spec = filter_properties.get('request_spec')
    if spec:
        volid = spec.get('volume_id')
    grouping = ('cluster' if backend_state.cluster_name else 'host')
    if filter_properties.get('new_size'):
        requested_size = (int(filter_properties.get('new_size')) - int(filter_properties.get('size')))
        LOG.debug('Checking    if    %(grouping)s    %(grouping_name)s    can    extend    the    volume    %(id)s    in    %(size)s    GB', {'grouping': grouping, 'grouping_name': backend_state.backend_id, 'id': volid, 'size': requested_size})
    else:
        requested_size = filter_properties.get('size')
        LOG.debug('Checking    if    %(grouping)s    %(grouping_name)s    can    create    a    %(size)s    GB    volume    (%(id)s)', {'grouping': grouping, 'grouping_name': backend_state.backend_id, 'id': volid, 'size': requested_size})
    if (requested_size == 0):
        return True
    if (backend_state.free_capacity_gb is None):
        LOG.error('Free    capacity    not    set:    volume    node    info    collection    broken.')
        return False
    free_space = backend_state.free_capacity_gb
    total_space = backend_state.total_capacity_gb
    reserved = (float(backend_state.reserved_percentage) / 100)
    if (free_space in ['infinite', 'unknown']):
        return True
    elif (total_space in ['infinite', 'unknown']):
        if (reserved == 0):
            return True
        LOG.debug("Cannot    calculate    GB    of    reserved    space    (%s%%)    with    backend's    reported    total    capacity    '%s'", backend_state.reserved_percentage, total_space)
        return False
    total = float(total_space)
    if (total <= 0):
        LOG.warning('Insufficient    free    space    for    volume    creation.    Total    capacity    is    %(total).2f    on    %(grouping)s    %(grouping_name)s.', {'total': total, 'grouping': grouping, 'grouping_name': backend_state.backend_id})
        return False
    free = (free_space - math.floor((total * reserved)))
    thin = True
    vol_type = (filter_properties.get('volume_type', {}) or {})
    provision_type = vol_type.get('extra_specs', {}).get('provisioning:type')
    if (provision_type == 'thick'):
        thin = False
    if (thin and backend_state.thin_provisioning_support and (backend_state.max_over_subscription_ratio >= 1)):
        provisioned_ratio = ((backend_state.provisioned_capacity_gb + requested_size) / total)
        if (provisioned_ratio > backend_state.max_over_subscription_ratio):
            msg_args = {'provisioned_ratio': provisioned_ratio, 'oversub_ratio': backend_state.max_over_subscription_ratio, 'grouping': grouping, 'grouping_name': backend_state.backend_id}
            LOG.warning('Insufficient    free    space    for    thin    provisioning.    The    ratio    of    provisioned    capacity    over    total    capacity    %(provisioned_ratio).2f    has    exceeded    the    maximum    over    subscription    ratio    %(oversub_ratio).2f    on    %(grouping)s    %(grouping_name)s.', msg_args)
            return False
        else:
            adjusted_free_virtual = (free * backend_state.max_over_subscription_ratio)
            res = (adjusted_free_virtual >= requested_size)
            if (not res):
                msg_args = {'available': adjusted_free_virtual, 'size': requested_size, 'grouping': grouping, 'grouping_name': backend_state.backend_id}
                LOG.warning('Insufficient    free    virtual    space    (%(available)sGB)    to    accomodate    thin    provisioned    %(size)sGB    volume    on    %(grouping)s    %(grouping_name)s.', msg_args)
            return res
    elif (thin and backend_state.thin_provisioning_support):
        LOG.warning('Filtering    out    %(grouping)s    %(grouping_name)s    with    an    invalid    maximum    over    subscription    ratio    of    %(oversub_ratio).2f.    The    ratio    should    be    a    minimum    of    1.0.', {'oversub_ratio': backend_state.max_over_subscription_ratio, 'grouping': grouping, 'grouping_name': backend_state.backend_id})
        return False
    msg_args = {'grouping_name': backend_state.backend_id, 'grouping': grouping, 'requested': requested_size, 'available': free}
    if (free < requested_size):
        LOG.warning('Insufficient    free    space    for    volume    creation    on    %(grouping)s    %(grouping_name)s    (requested    /    avail):    %(requested)s/%(available)s', msg_args)
        return False
    LOG.debug('Space    information    for    volume    creation    on    %(grouping)s    %(grouping_name)s    (requested    /    avail):    %(requested)s/%(available)s', msg_args)
    return True
