'Return a list of all running services.
Filter by host & service name.'

def index(self, req):

    context = req.environ['cinder.context']
    authorize(context, action='index')
    detailed = self.ext_mgr.is_loaded('os-extended-services')
    now = timeutils.utcnow(with_timezone=True)
    filters = {}
    if ('host' in req.GET):
        filters['host'] = req.GET['host']
    if ('binary' in req.GET):
        filters['binary'] = req.GET['binary']
    services = objects.ServiceList.get_all(context, filters)
    svcs = []
    for svc in services:
        updated_at = svc.updated_at
        delta = (now - (svc.updated_at or svc.created_at))
        delta_sec = delta.total_seconds()
        if svc.modified_at:
            delta_mod = (now - svc.modified_at)
            if (abs(delta_sec) >= abs(delta_mod.total_seconds())):
                updated_at = svc.modified_at
        alive = (abs(delta_sec) <= CONF.service_down_time)
        art = ('up' if alive else 'down')
        active = 'enabled'
        if svc.disabled:
            active = 'disabled'
        if updated_at:
            updated_at = timeutils.normalize_time(updated_at)
        ret_fields = {'binary': svc.binary, 'host': svc.host, 'zone': svc.availability_zone, 'status': active, 'state': art, 'updated_at': updated_at}
        if req.api_version_request.matches('3.7'):
            ret_fields['cluster'] = svc.cluster_name
        if detailed:
            ret_fields['disabled_reason'] = svc.disabled_reason
            if (svc.binary == 'cinder-volume'):
                ret_fields['replication_status'] = svc.replication_status
                ret_fields['active_backend_id'] = svc.active_backend_id
                ret_fields['frozen'] = svc.frozen
        svcs.append(ret_fields)
    return {'services': svcs}
