当前位置:   article > 正文

OpenStack使用glance命令创建镜像_glance image-create

glance image-create

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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
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                              |
+------------------+--------------------------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
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]
  • 1
  • 2

需要加载用户身份变量,执行以下代码

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

或者将以上代码保存到一个以 .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 |
+--------------------------------------+-----------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/306901?site
推荐阅读
相关标签
  

闽ICP备14008679号