当前位置: 首页 > 工具软件 > Glance > 使用案例 >

关于OpenStack的Glance服务使用

壤驷英叡
2023-12-01

Glance提供 Image Service服务,功能是管理 Image,让用户能够发现、获取和保存 Image。提供 REST API (request应用接口)让用户能够查询和获取 image 的元数据(描述数据的数据)和 image 本身支持多种方式存储 image,包括普通的文件系统、Swift、Amazon S3 等对 Instance 执行 Snapshot 创建新的 image。

  glance只记录镜像有没有,在哪,但是对镜像本身不做管理。当接收到请求之后会分解请求,请求正确且通过keystone认证之后就会到数据库中找到镜像,然后告知用户镜像在哪里,至于用户拿到的镜像能不能使用glance是不管的。

————————————————
版权声明:本文为CSDN博主「鬼刺」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_35550345/article/details/87797386

关于Glance的有关使用

一、使用镜像文件CentOS_7.2_x86_64_XD.qcow2 创建glance镜像名为Centos7.2,格式为qcow2
1、镜像文件存放的地方

[root@controller bin]# ll /opt/iaas/images/
total 1246811
-rw-r--r--. 1 root root 283181056 Nov  2  2017 CentOS_6.5_x86_64_XD.qcow2
-rw-r--r--. 1 root root 400752640 Nov  2  2017 CentOS_7.2_x86_64_XD.qcow2
-rw-r--r--. 1 root root 592800256 Nov  2  2017 MySQL_5.6_XD.qcow2
[root@controller bin]# 

2、上传镜像

[root@controller ~]# glance image-create --name "CentOS7.2" --disk-format qcow2 --container-format bare  --progress < /opt/iaas/images/CentOS
_7.2_x86_64_XD.qcow2 [=============================>] 100%
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ea197f4c679b8e1ce34c0aa70ae2a94a     |
| container_format | bare                                 |
| created_at       | 2018-04-28T11:41:16Z                 |
| disk_format      | qcow2                                |
| id               | 61dd7bd1-6ee3-4616-bf83-d86a15ce683d |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | CentOS7.2                            |
| owner            | b9fe13cfc7d6462bbde5e041ef898da4     |
| protected        | False                                |
| size             | 400752640                            |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2018-04-28T11:41:19Z                 |
| virtual_size     | None                                 |
| visibility       | private                              |
+------------------+--------------------------------------+

二、使用glance相关命令查询glance镜像列表,并查询centos7.2镜像的详细信息

[root@controller bin]# glance image-list
+--------------------------------------+---------+
| ID                                   | Name    |
+--------------------------------------+---------+
| 6babbb04-da4b-4197-a34f-7a39026bf1d8 | centos7 |
+--------------------------------------+---------+
[root@controller bin]# glance image-show 6babbb04-da4b-4197-a34f-7a39026bf1d8 
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ea197f4c679b8e1ce34c0aa70ae2a94a     |
| container_format | bare                                 |
| created_at       | 2019-12-12T02:32:35Z                 |
| disk_format      | qcow2                                |
| id               | 6babbb04-da4b-4197                 -a34f-7a39026bf1d8 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | centos7                              |
| owner            | 5cb6243755824171b7e0873b18847545     |
| protected        | False                                |
| size             | 400752640                            |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2019-12-12T02:32:52Z                 |
| virtual_size     | None                                 |
| visibility       | private                              |
+------------------+--------------------------------------+

三、使用systemctl相关命令,在一条命令中查询glance组件中所有服务状态信息

[root@controller bin]# systemctl status openstack-glance-api,service openstack-glance-registry.service
● openstack-glance-api\x2cservice.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)

● openstack-glance-registry.service - OpenStack Image Service (code-named Glance) Registry server
   Loaded: loaded (/usr/lib/systemd/system/openstack-glance-registry.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-12-11 16:18:09 EST; 1 day 5h ago
 Main PID: 19695 (glance-registry)
   CGroup: /system.slice/openstack-glance-registry.service
           ├─19695 /usr/bin/python2 /usr/bin/glance-registry
           ├─19749 /usr/bin/python2 /usr/bin/glance-registry
           ├─19750 /usr/bin/python2 /usr/bin/glance-registry
           ├─19751 /usr/bin/python2 /usr/bin/glance-registry
           ├─19752 /usr/bin/python2 /usr/bin/glance-registry
           ├─19753 /usr/bin/python2 /usr/bin/glance-registry
           ├─19754 /usr/bin/python2 /usr/bin/glance-registry
           ├─19755 /usr/bin/python2 /usr/bin/glance-registry
           ├─19756 /usr/bin/python2 /usr/bin/glance-registry
           ├─19757 /usr/bin/python2 /usr/bin/glance-registry
           ├─19758 /usr/bin/python2 /usr/bin/glance-registry
           ├─19759 /usr/bin/python2 /usr/bin/glance-registry
           ├─19760 /usr/bin/python2 /usr/bin/glance-registry
           ├─19761 /usr/bin/python2 /usr/bin/glance-registry
           ├─19762 /usr/bin/python2 /usr/bin/glance-registry
           ├─19763 /usr/bin/python2 /usr/bin/glance-registry
           └─19764 /usr/bin/python2 /usr/bin/glance-registry

Dec 11 20:38:13 controller glance-registry[19695]: /usr/lib/py...
Dec 11 20:38:13 controller glance-registry[19695]: expire_on_c...
Dec 11 20:48:13 controller glance-registry[19695]: /usr/lib/py...
Dec 11 20:48:13 controller glance-registry[19695]: expire_on_c...
Dec 11 21:11:26 controller glance-registry[19695]: /usr/lib/py...
Dec 11 21:11:26 controller glance-registry[19695]: expire_on_c...
Dec 11 21:11:37 controller glance-registry[19695]: /usr/lib/py...
Dec 11 21:11:37 controller glance-registry[19695]: expire_on_c...
Dec 11 21:12:45 controller glance-registry[19695]: /usr/lib/py...
Dec 11 21:12:45 controller glance-registry[19695]: expire_on_c...
Hint: Some lines were ellipsized, use -l to show in full.
[root@controller bin]# 

四、帮助

[root@controller bin]# glance help

例如,创建镜像的参数

[root@controller bin]# glance help image-create
usage: glance image-create [--architecture <ARCHITECTURE>]
                           [--protected [True|False]] [--name <NAME>]
                           [--instance-uuid <INSTANCE_UUID>]
                           [--min-disk <MIN_DISK>] [--visibility <VISIBILITY>]
                           [--kernel-id <KERNEL_ID>]
                           [--tags <TAGS> [<TAGS> ...]]
                           [--os-version <OS_VERSION>]
                           [--disk-format <DISK_FORMAT>]
                           [--os-distro <OS_DISTRO>] [--id <ID>]
                           [--owner <OWNER>] [--ramdisk-id <RAMDISK_ID>]
                           [--min-ram <MIN_RAM>]
                           [--container-format <CONTAINER_FORMAT>]
                           [--property <key=value>] [--file <FILE>]
                           [--progress]

Create a new image.

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
  --os-version <OS_VERSION>
                        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
  --os-distro <OS_DISTRO>
                        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.

Run `glance --os-image-api-version 1 help image-create` for v1 help
 类似资料: