wsme and pecan in ironic

来源:互联网 发布:php acl访问控制列表 编辑:程序博客网 时间:2024/06/08 16:36

和openstack中的其他模块一样,ironic也大量使用开源或成熟的Python类库,创建pecan项目之后,在config.py中我们知道:

'root': 'ironic.api.controllers.root.RootController',

即入口在RooController中,首先我们就会发现wsme的引入

wsme: Web Services Made Easy

本身的目的也是让写WSGI的项目更加容易,配上pecan的框架就更加强大了,

阅读pecan的官方文档https://pecan.readthedocs.org/en/latest/routing.html

WSME的官方文档:https://pythonhosted.org/WSME/

都有expose方法,只有被expose()装饰的方法才会暴漏给rest call。

wsme.types包替我们做了很多类型校验的工作,而wsmeext.pecan则可以理解为pecan使用wsme的一个适配器,可以更加方便的使用“

wsmeext.pecan.wsexpose(return_type,*arg_types, **options)

详情见http://wsme.readthedocs.org/en/latest/integrate.html,此处还有很多其他框架或库与wsme的适配器

要在pecan中使用wsme,配置很简单,在pecan项目的confiy.py中添加(ironic)

# WSME Configurations
# See https://wsme.readthedocs.org/en/latest/integrate.html#configuration
wsme = {
    'debug': False,
}

pecan中有几个特殊的方法_lookup(),_default(), and_route()

在RootController中我们可以看到_route()方法的使用,添加默人的route路径到“/v1”

通过RootController,进入:

    nodes = node.NodesController()
    ports = port.PortsController()
    chassis = chassis.ChassisController()
    drivers = driver.DriversController()

我们可以看到    @wsme.validate(types.uuid_or_name, [NodePatchType]), 可以看到在/ironic/api/controllers/v1/types.py中定义了很多user define的类,并

重载了方法validate,用于验证input/output数据是否为定义类型


根据pecan的文档,ironic对外提供的rest为:

/v1/nodes/

/v1/nodes/{uuid}/states

/v1/nodes/{uuid}/states/console

/v1/nodes/ports

/v1/nodes/{uuid}/vendor_passthru

/v1/nodes/{uuid}/management/boot_device

/v1/nodes/{uuid}/maintence

/v1/ports/

/v1/drivers/

/v1/drivers/{name}/vendor_passthru

/v1/chassis/

/v1/chassis/{chassisuuid}/nodes

详细定义在:http://docs.openstack.org/developer/ironic/webapi/v1.html

https://media.readthedocs.org/pdf/pecan/latest/pecan.pdf

对于嵌套的controller,比如chassis嵌套nodes,nodes controller嵌套了states,management等,drivers controller嵌套了vendor_passthru等

如果父controller,比如chassis,nodes,drivers 对应的controller包含get_one或者get方法(先check get_one),那么PeCan会将其参数传给子controller

这也就是嵌套的controller情况下诸如 /v1/chassis/{chassisuuid}/nodes等rest call 是如何形成的






0 0