OpenStack使用glance命令创建镜像

OpenStack使用glance命令创建镜像

本文主要介绍如何使用glance命令上传镜像

1.选项

Optional arguments:
  --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          Descriptive name for the image
  --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 
                        Amount of disk space (in GB) required to boot image.
  --visibility 
                        Scope of image accessibility Valid values: public,
                        private
  --kernel-id 
                        ID of image stored in Glance that should be used as
                        the kernel when booting an AMI-style image.
  --tags  [ ...]
                        List of strings related to the image
                        Operating system version as specified by the
                        distributor
  --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              An identifier for the image
  --owner        Owner of the image
  --ramdisk-id 
                        ID of image stored in Glance that should be used as
                        the ramdisk when booting an AMI-style image.
  --min-ram    Amount of ram (in MB) required to boot image.
  --container-format 
                        Format of the container Valid values: ami, ari, aki,
                        bare, ovf, ova, docker
  --property 
                        Arbitrary property to associate with image. May be
                        used multiple times.
  --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部分选项翻译

  1. –architecture 指定操作系统架构
  2. –protected 如果为True,镜像将不可删除
  3. –name 指定镜像名称
  4. –min-disk 启动镜像所需的最小的磁盘空间(以GB为单位)
  5. –min-ram 启动镜像所需的最小内存大小(以MB为单位)
  6. –id 镜像的ID
  7. –owner 镜像的所有者
  8. –disk-format 指定镜像的格式(ami, ari, aki, vhd,vmdk, raw, qcow2, vdi, iso)
  9. –file 指定镜像文件
  10. –container 指定容器格式(ami, ari, aki,bare, ovf, ova, docker)
  11. ----visibility 镜像的可见范围(public,private)或?? --public & --private & --is-public=True
  12. –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注意事项

  1. 命令中加粗的为必选项
    glance image-create --name centos7.2 \
    –disk-format qcow2 --container bare --file 镜像文件
  2. 要注意身份验证问题,否则容易出现下列问题
[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 |
+--------------------------------------+-----------+

你可能感兴趣的:(OpenStack)