'Returns a list of security groups.'

@wsgi.Controller.api_version('2.1', MAX_PROXY_API_SUPPORT_VERSION)
@extensions.expected_errors(404)
def index(self, req):

    context = _authorize_context(req)
    search_opts = {}
    search_opts.update(req.GET)
    project_id = context.project_id
    raw_groups = self.security_group_api.list(context, project=project_id, search_opts=search_opts)
    limited_list = common.limited(raw_groups, req)
    result = [self._format_security_group(context, group) for group in limited_list]
    return {'security_groups': list(sorted(result, key=(lambda k: (k['tenant_id'], k['name']))))}
