Glance可以做到的不仅是从命令行中把镜像添加到集群中。这里有些使用例子。

1.把镜像添加到glance中。

glance image-create --name test --min-disk 1 --min-ram 768 --file \ centos-6.5-20140117.0.x86_64.qcow2 --is-public True --property net_model=e1000 --property \ disk_bus=ide --disk-format=qcow2 --container-format ovf --progress


这个示例使用以下参数:

  --id <IMAGE_ID>    镜像的ID
--name <NAME>      镜像的名称
--store <STORE>    储存的镜像上传到
--disk-format <DISK_FORMAT>
                    镜像的格式。可以接受的格式包含: ami,ari, aki, vhd, vmdk, raw, qcow2, vdi, and iso.
--container-format <CONTAINER_FORMAT>
                    镜像容器的格式。可以接受的格式包含:ami,ari, aki, bare, and ovf.
--owner <TENANT_ID>   拥有该镜像的租户
--size <SIZE>      镜像的大小(以bytes表示). 一般只与'--location'和'--copy_from'一起使用。
--min-disk <DISK_GB>     启动镜像所需的最小硬盘空间(用gigabytes表示).
--min-ram <DISK_RAM>     启动镜像所需的最小内存数量(用megabytes表示).
--location <IMAGE_URL>
                    镜像所在位置的URL。例如,如果镜像储存在swift中,
                    你可以指定:'swift://account:key@example.com/container/obj'。
--file <FILE>      在创建过程中将要被上传的本地文件(包括硬盘镜像)。
                    另外,镜像也可以通过stdin传递给客户端。 
--checksum <CHECKSUM>
                    被Glance使用的可用于认证的镜像数据的哈希值,
                    在此请提供一个md5校验值。
--copy-from <IMAGE_URL>
                    用法和'--location'参数相似,但表明Glance服务器应该能立即从镜像所储存的地方拷贝数据并储存。                                        
--is-public [True|False]
                    表示镜像是否能被公众访问。
--is-protected [True|False]
                    用于避免镜像被删除。
--property <key=value>
                    与镜像有关的任意的属性。可以使用很多次。
--human-readable     用对人友好的格式打印镜像的尺寸。 
--progress       显示上传的进度条

可以使用-property标识设置任何任意的属性。在镜像信息中可以查看这个属性:

glance image-show test



使用这个命令获取镜像列表:

glance image-list



你可以从OpenStack官方文档中的adding images(http://docs.openstack.org/grizzl ... /adding-images.html)获取更多信息。

其他例子:
*创建镜像

glance image-create --name "Window Server 2008 R2" --is-public=true --disk-format=qcow2 --container-format=ovf --file WIN2K8R2.qcow2


*转换(Transferring)一个镜像

glance image-create --name MSE-kl-test --disk-format=raw --container-format=bare --is-public=True --property hw_vif_model=e1000 --property hw_disk_bus=ide --file=MSE.raw


当从其他虚拟化平台迁移一个镜像过来时,经常需要通过–property维护一个非OpenStack的参数。

这个技巧是非常有用的,例如镜像是从其他像VMware那样的平台拿过来的,有像本例中所用的值:


hw_disk_bus=ide


这些值保存在glance数据库,当一个实例以镜像启动时用来转换至VM的参数。


*删除镜像

image-delete {image name}


*转换(Convert)镜像至另一种格式


qemu-img convert -f {initial format初始格式} -O {target format目标格式}  {source file源文件}  {destination file目标文件}



例如:


qemu-img convert -f vmdk -O qcow2 VM.vmdk VM.qcow2