0

在我的 keystone 中间件中,我试图调用 assignment_api 函数 get_project_by_name。

我试图通过使用依赖注入来做到这一点,但是,我在调试日志中看到了以下错误:

AttributeError:“ProjectsByDemand”对象没有属性“assignment_api”

请看下面的代码:

from keystone.openstack.common import log as logging
from keystone.common import dependency
from keystone import config
from keystone import exception
from keystone.common import cache
from keystone.common import wsgi

@dependency.requires('assignment_api')
class ProjectsByDemand(wsgi.Middleware):
  def __init__(self, app, conf):
    self.conf = conf
    self.app = app
    self.internal_l = ['admin','neutron','glance','cinder','nova']
    self.log = logging.getLogger(__name__)

   .
   .
   .

  def process_request(self, environ, start_response):
    auth = self.get_username(environ)
    if auth is not None:
      if auth[0] is not self.internal_l:
        self.log.debug('middleware-debug: Authenticating with: %s' % (auth[0]) )
        project_ref = self.assignment_api.get_project_by_name(username, "default")
        self.log.debug("middleware-debug: Project ref is: %s", project_ref)
    return self.app(environ, start_response)

知道缺少什么吗?

4

1 回答 1

0

您混合了制表符和空格,并且还弄乱了缩进,请尝试运行脚本python -tt来检查。

于 2015-05-19T14:29:30.667 回答