Queued:初始化镜像状态,在镜像文件刚刚被创建,在glance数据库中已经保存了镜像标示符,但还没有上传至glance中,此时的glance对镜像数据没有任何描述,其存储空间0
Saving:镜像的原始数据在上传中的一种过度状态,它产生在镜像数据上传至glance的过程中,一般来讲,glance收到一个image请求后,才将镜像上传给glance
Active:镜像成功上传完毕以后的一种状态,它表明glance中可用的镜像
Killed:镜像上传失败或者镜像文件不可读的情况下,glance将镜像状态设置成Killed
Deleted:镜像文件马上会被删除,只是当前glance这种仍然保留该镜像文件的相关信息和原始镜像数据
Pending_delete:
1.Image identifiers
Image 使用 URI 作为唯一标识,URL 符合以下格式 <Glance Server Location>/image/<ID>
2.Image Statuses
-
queued 标识该镜像ID已经被保留,但是镜像还未上传
-
saving 标识镜像正在被上传
-
active 标识镜像在 Glance 中完全可用
-
killed 标识镜像上传过程中出错,镜像完全不可用
-
deleted Glance 已经保存了镜像的信息,但是无法继续使用。在此状态下的镜像稍后将会被自动清除
-
pending_delete 类似于 deleted,区别在于 Glance 还没有移除镜 像数据。在此状态下的镜像是可以被恢复的
3.Task Statuses
-
pending 在 Glance 中保留 task identifier。但此时还没有进程开始执行
-
processing 任务已被底层执行者选中,并且后端 Glance 根据任务类型开始执行对应的逻辑操作
-
success 表示该任务已成功运行。在任务的“result”域中会显示关于输出结果的更多细节
-
failure 表示在任务的执行过程中发生了一个错误,并且它不能继续执行下去。任务的 “message”域展示了是什么错误
4.磁盘和容器格式
Disk Format:虚拟机镜像的磁盘格式是底层磁盘镜像的格式
Container Format:container 格式表示虚拟机镜像是否在一个包括虚拟机的 metadata 文件格式中;当 disk format 为 aki ari ami 时,disk format 和 container format 一致
5.Image Registries
使用 Glance,镜像 metadata 可以注册至 image registries
只要为 image metadata 提供了 rest like API,任何 web 程序可以作为 image registries 与 Glance 对接
6.组件及架构
Glance 主要由三个部分构成:glance-api、glance-registry 以及 image store
-
Glance-api 接收 REST API 的请求,类似 nova-api,都是接收 REST API 请求,然后通过其 他模块(glance-registry 及 image store)来完成诸如镜像的查找、获取、上传、 删除等操作,默认监听端口 9292
-
glance-registry 用于与 MySQL 数据库交互,用于存储或获取镜像的元数据 (metadata);glance-registry 监听端口 9191。Glance 的数据库中有两张表,一张是 image 表,另一张是 image property 表。Image 表 保存了镜像格式、大小等信息;image property 表则主要保存镜像的定制化信息
-
image store 是一个存储的接口层,通过这个接口,glance 可以获取镜像, image store 支持的存储有 Amazon 的 S3、OpenStack 本身的 Swift,还有诸 如 ceph,sheepdog,GlusterFS 等分布式存储。 Image store 是镜像保存与获取的接口,它仅仅是一个接口层,具体的实现需要外部的存储支持,支持的接口有 Amazon S3、GlusterFS、Swift,sheepdog, ceph 等
7.镜像缓存机制
Glance 中的镜像文件不管用什么样的方式存储,都是存储在 server 端,用户 在创建实例的前要先从 server 端获取相应镜像,再到本地根据配置进行相关的处 理。有些镜像文件非常的大,在从服务端传到客户端要花费大量的时间,使实例 的启动变得非常慢,对于一些特定的应用来说会比较吃力,如果利用 Glance 的 缓存机制,预先通过命令将特定的镜像进行缓存,缓存到需要的计算节点上会有 很好的效果。对镜像进行缓存变相的增加了镜像存储的可靠性
本地缓存的另一个好处就是,你可以通过它实现镜像的 base imag(或者叫金 手指,差异镜像等)的功能。比如一些分布式自动化测试平台对于运行时间的要求是非常的高的就可以利用缓存功能
Glance 的缓存服务是需要在配置文件中进行配置开启的。Glance 缓存还提供了缓存,删除,根据配置的过期时间删除等众多的功能
openstack命令
[root@controller ~]# openstack image list
[root@controller ~]# openstack image create --container-format <container-format> #指定容器格式 --disk-format <disk-format> #指定磁盘格式 --min-disk <disk-gb> #指定磁盘大小 --min-ram <ram-mb> #指定内存大小 --file <file> #指定文件路径 <image-name> #指定镜像名称 [root@controller ~]# openstack image create --container-format bare --disk-format qcow2 --file /root/cirros-0.3.4-x86_64-disk.img cirros
更新镜像
[root@controller ~]# openstack image set --name=cirros mycirros
查看镜像详细信息
[root@controller ~]# openstack image show 镜像ID
镜像导出
[root@controller ~]# openstack image save --file /root/centos <image>
镜像删除
[root@controller ~]# openstack image delete 镜像ID
glance命令
镜像列表信息
[root@controller ~]# glance image-list
+----+------+
| ID | Name |
+----+------+
+----+------+
[root@controller ~]# glance image-create --name cirros --disk-format qcow2 --container-format bare < cirros-0.3.4-x86_64-disk.img
[root@controller ~]# glance image-update --name=cirros mycirros
查看镜像详细信息
[root@controller ~]# glance image-show 镜像ID
镜像导出
[root@controller ~]# glance image-download --file /root/centos --progress <image_id>
镜像删除
[root@controller ~]# glance image-delete 镜像ID
glance api
从本地文件上传 image
file 是本地文件的全路经,endpoint 是 glance 的 endpoit
from glanceclient import Client endpoint = get_service_endpoint('glance') glance = Client('1', endpoint, token) meta = { 'name': image_name, 'is_public': True, 'disk_format': disk_format, 'container_format': container_format, } image = glance.images.create(**meta) image.update(data=open(file, 'rb'))
从远程 URL 上传 image
file_path 就是相关 image 的 URL
from glanceclient import Client endpoint = get_service_endpoint('glance') glance = Client('1', endpoint, token) meta = { 'name': image_name, 'is_public': True, 'disk_format': disk_format, 'container_format': container_format, 'copy_from': file_path, } image = glance.images.create(**meta)