Openstack liberty Glance上传镜像源码分析

该文同时发布在[ceph中国社区],署名为Thomas,另外截图不是很清晰,有需要的读者,可以留言索要,谢谢!

在Openstack中创建云主机,首先得有镜像,而Glance模块提供镜像服务功能,包括:镜像的发现、检索及存储等,主要包括:glance-api和glance-registery两个服务,分别负责镜像的存储和元数据管理。下面基于源码,分析下镜像的上传过程。

上传镜像

先通过glance CLI上传镜像,来直观的了解下镜像上传的过程:

# glance --debug image-create --file centos-7.0-x64-20g.qcow2 --disk-format raw --container-format bare --visibility public

通过在命令行中开启--debug,我们可以发现,上传镜像过程中glance CLI会发送如下三个不同的请求:
这里写图片描述

这里写图片描述

这里写图片描述

那这三个请求分别干了什么事呢? 下面我们来一一分解。

获取镜像属性定义

通过glance/api/v2/router.py.API中定义的路由映射,我们知道上述的第一个请求由glance/api/v2/schemas.py.Controller.image方法处理,如下:

#路由映射,代码节选
#完整的函数实现,请参考glance/api/v2/router.py.API.__init__
def __init__(self, mapper):
    #从/etc/glance/schema-image.json文件加载用户定义属性
    custom_image_properties = images.load_custom_properties()
    #创建glance/api/v2/schemas.py.Controller实例
    schemas_resource = 
            schemas.create_resource(custom_image_properties)
    #定义路由映射:
    #curl -X GET /schemas/image  -> shemas_resource.image
    mapper.connect('/schemas/image',
                       controller=schemas_resource,
                       action='image',
                       conditions={
  'method': ['GET']})

#glance/api/v2/schemas.py.Controller.image
"""返回一个镜像属性字典,结构如下:
[
    'name': image,
    'properties':xxx
    'additionalProperties':xxx
    'definitions':xxx
    'required':xxx
    'links':xxx
]
"""字典值请看下面的分析过程
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值