'Gets a host\'s goodness rating based on its goodness function.'

def _check_goodness_function(self, stats):

    goodness_rating = 0
    if (stats['goodness_function'] is None):
        LOG.warning('Goodness    function    not    set    ::    defaulting    to    minimal    goodness    rating    of    0')
    else:
        try:
            goodness_result = self._run_evaluator(stats['goodness_function'], stats)
        except Exception as ex:
            LOG.warning("Error    in    goodness_function    function    '%(function)s'    :    '%(error)s'    ::    Defaulting    to    a    goodness    of    0", {'function': stats['goodness_function'], 'error': ex})
            return goodness_rating
        if (type(goodness_result) is bool):
            if goodness_result:
                goodness_rating = 100
        elif ((goodness_result < 0) or (goodness_result > 100)):
            LOG.warning("Invalid    goodness    result.        Result    must    be    between    0    and    100.        Result    generated:    '%s'    ::    Defaulting    to    a    goodness    of    0", goodness_result)
        else:
            goodness_rating = goodness_result
    return goodness_rating
