OpenStack使用glance命令创建镜像
本文主要介绍如何使用glance命令上传镜像
1.选项
Optional arguments:
--architecture <ARCHITECTURE>
Operating system architecture as specified in
http://docs.openstack.org/trunk/openstack-
compute/admin/content/adding-images.html
--protected [True|False]
If true, image will not be deletable.
--name <NAME> Descriptive name for the image
--instance-uuid <INSTANCE_UUID>
Metadata which can be used to record which instance
this image is associated with. (Informational only,
does not create an instance snapshot.)
--min-disk <MIN_DISK>
Amount of disk space (in GB) required to boot image.
--visibility <VISIBILITY>
Scope of image accessibility Valid values: public,
private
--kernel-id <KERNEL_ID>
ID of image stored in Glance that should be used as
the kernel when booting an AMI-style image.
--tags <TAGS> [<TAGS> ...]
List of strings related to the image
Operating system version as specified by the
distributor
--disk-format <DISK_FORMAT>
Format of the disk Valid values: ami, ari, aki, vhd,
vmdk, raw, qcow2, vdi, iso
Common name of operating system distribution as
specified in http://docs.openstack.org/trunk
/openstack-compute/admin/content/adding-images.html
--id <ID> An identifier for the image
--owner <OWNER> Owner of the image
--ramdisk-id <RAMDISK_ID>
ID of image stored in Glance that should be used as
the ramdisk when booting an AMI-style image.
--min-ram <MIN_RAM> Amount of ram (in MB) required to boot image.
--container-format <CONTAINER_FORMAT>
Format of the container Valid values: ami, ari, aki,
bare, ovf, ova, docker
--property <key=value>
Arbitrary property to associate with image. May be
used multiple times.
--file <FILE> Local file that contains disk image to be uploaded
during creation. Alternatively, the image data can be
passed to the client via stdin.
--progress Show upload progress bar.
1.1部分选项翻译
- –architecture 指定操作系统架构
- –protected 如果为True,镜像将不可删除
- –name 指定镜像名称
- –min-disk 启动镜像所需的最小的磁盘空间(以GB为单位)
- –min-ram 启动镜像所需的最小内存大小(以MB为单位)
- –id 镜像的ID
- –owner 镜像的所有者
- –disk-format 指定镜像的格式(ami, ari, aki, vhd,vmdk, raw, qcow2, vdi, iso)
- –file 指定镜像文件
- –container 指定容器格式(ami, ari, aki,bare, ovf, ova, docker)
- ----visibility 镜像的可见范围(public,private)或?? --public & --private & --is-public=True
- –progress 进度显示上传进度条
2.创建镜像
2.1创建一个Centos镜像
[root@controller ~]# glance image-create --name centos7.2 --disk-format qcow2 --container bare --file /opt/iaas/images/CentOS_7.2_x86_64_XD.qcow2
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | ea197f4c679b8e1ce34c0aa70ae2a94a |
| container_format | bare |
| created_at | 2019-10-08T19:51:27Z |
| disk_format | qcow2 |
| id | d1bf479f-d82a-4be3-8af4-6c0586f12f5e |
| min_disk | 0 |
| min_ram | 0 |
| name | centos7.2 |
| owner | 76a36b75f7124d26871eaf6977f4a3ba |
| protected | False |
| size | 400752640 |
| status | active |
| tags | [] |
| updated_at | 2019-10-08T19:51:33Z |
| virtual_size | None |
| visibility | private |
+------------------+--------------------------------------+
2.2注意事项
- 命令中加粗的为必选项
glance image-create --name centos7.2 \
–disk-format qcow2 --container bare --file 镜像文件 - 要注意身份验证问题,否则容易出现下列问题
[root@controller ~]# glance image-list
You must provide a username via either --os-username or env[OS_USERNAME]
需要加载用户身份变量,执行以下代码
export OS_PROJECT_DOMAIN_NAME=demo
export OS_USER_DOMAIN_NAME=demo
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=000000 #此处以实际密码为准
export OS_AUTH_URL=http://controller:35357/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
或者将以上代码保存到一个以 .sh (这里我保存在/etc/keystone/admin-openrc.sh 这个文件中)结尾的文件中然后执行下方操作
[root@controller ~]# source /etc/keystone/admin-openrc.sh
[root@controller ~]# glance image-list
+--------------------------------------+-----------+
| ID | Name |
+--------------------------------------+-----------+
| d1bf479f-d82a-4be3-8af4-6c0586f12f5e | centos7.2 |
+--------------------------------------+-----------+