Keystone中间件(openstack)中的依赖注入

2024-05-20 10:26:42 发布

您现在位置:Python中文网/ 问答频道 /正文

在我的keystone中间件中,我尝试按名称调用赋值函数getproject。在

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

AttributeError: 'ProjectsByDemand' object has no attribute '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)

知道少了什么吗?在


Tags: fromdebugimportselfprojectauthlogapi