'Moved from nova.utils
Check whether a service is up based on last heartbeat.'

def is_up(self, service_ref):

    last_heartbeat = (service_ref.get('last_seen_up') or service_ref['created_at'])
    if isinstance(last_heartbeat, six.string_types):
        last_heartbeat = timeutils.parse_strtime(last_heartbeat)
    else:
        last_heartbeat = last_heartbeat.replace(tzinfo=None)
    elapsed = timeutils.delta_seconds(last_heartbeat, timeutils.utcnow())
    is_up = (abs(elapsed) <= self.service_down_time)
    if (not is_up):
        LOG.debug('Seems    service    %(binary)s    on    host    %(host)s    is    down.    Last    heartbeat    was    %(lhb)s.    Elapsed    time    is    %(el)s', {'binary': service_ref.get('binary'), 'host': service_ref.get('host'), 'lhb': str(last_heartbeat), 'el': str(elapsed)})
    return is_up
