'Returns a list of server groups.'

@extensions.expected_errors(())
def index(self, req):

    context = _authorize_context(req, 'index')
    project_id = context.project_id
    if (('all_projects' in req.GET) and context.is_admin):
        sgs = objects.InstanceGroupList.get_all(context)
    else:
        sgs = objects.InstanceGroupList.get_by_project_id(context, project_id)
    limited_list = common.limited(sgs.objects, req)
    result = [self._format_server_group(context, group, req) for group in limited_list]
    return {'server_groups': result}
