ironic pecan hooks

查阅ironic的源代码时,看到:

pecan.request.rpcapi.change_node_power_state(pecan.request.context,rpc_node.uuid, target,topic)

比较奇怪的是pecan.request.rpcapi对应的是哪个类,虽然知道对应的是rpcapi.ConductorAPI(),但不知道为什么


关于pecan的hooks详情可以参考http://pecan.readthedocs.org/en/latest/pecan_hooks.html

我们理解的钩子,可以非常方便的接受到request时或request之后做一些巧妙地工作,举上面的例子:

实现类:

class RPCHook(hooks.PecanHook):
    """Attach the rpcapi object to the request so controllers can get to it."""

    def before(self, state):
        state.request.rpcapi = rpcapi.ConductorAPI()


指明request.rpcapi=rpcapi.ConductorAPI(),则之后request.rpcapi被后者代替,在ironic/app.py的setup方法中:

app_hooks = [hooks.ConfigHook(),
                 hooks.DBHook(),
                 hooks.ContextHook(pecan_config.app.acl_public_routes),
                 hooks.RPCHook(),
                 hooks.NoExceptionTracebackHook()]

app = pecan.make_app(
        pecan_config.app.root,
        static_root=pecan_config.app.static_root,
        debug=CONF.pecan_debug,
        force_canonical=getattr(pecan_config.app, 'force_canonical', True),
        hooks=app_hooks,
        wrap_app=middleware.ParsableErrorMiddleware,
    )

有一批钩子设置成功。

根则在cmd目录下的api.py的main方法中:

wsgi = simple_server.make_server(
            host, port,
            app.VersionSelectorApplication(),
            server_class=ThreadedSimpleServer)

在启动服务时候钩子进行设置





你可能感兴趣的:(ironic pecan hooks)