wsme and pecan in ironic

和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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值