Glance是OpenStack镜像服务组件,负责虚拟机镜像的查找、注册和检索。简单来说,Glance就是我们用来查找、注册和检索虚拟机镜像的地方。这个镜像并不是我们常见的操作系统的ISO镜像,而是特定制作的,用于产生虚拟机系统盘的模板。Glance提供RESTful API来查询虚拟机镜像的metadata及获取镜像。值得注意的是,Glance并不负责镜像的存储,而是将镜像保存到多种后端存储上,比如简单的文件存储或者对象存储。
创建一个centos7.2的镜像
[root@localhost ~(keystone_admin)]# ls
anaconda-ks.cfg Desktop Downloads keystonerc_demo original-ks.cfg Pictures Templates
CentOS7.2.qcow2 Documents keystonerc_admin Music packstack-answers-20240318-231803.txt Public Videos
[root@localhost ~(keystone_admin)]# glance image-create --name "centos7.2" --disk-format qcow2 --container-format bare --progress < CentOS7.2.qcow2
[=============================>] 100%
+------------------+----------------------------------------------------------------------------------+
| Property | Value |
+------------------+----------------------------------------------------------------------------------+
| checksum | ad11feb5af04f08d74ff6f4cb14527fa |
| container_format | bare |
| created_at | 2024-03-22T06:48:07Z |
| disk_format | qcow2 |
| id | 1f9b092d-68fa-4856-a61c-cf51330789ff |
| min_disk | 0 |
| min_ram | 0 |
| name | centos7.2 |
| os_hash_algo | sha512 |
| os_hash_value | 113e5609932b8c161fd4717896c4583f35efeeacc3b8c44380acc4381cc2a1d4121b38a03b03815f |
| | 1868e008e1e30d03b9cf5a3ec6129987f20f33fb77d27bad |
| os_hidden | False |
| owner | 009a94428fb84a0db16aa4a1adab9a35 |
| protected | False |
| size | 1373306880 |
| status | active |
| tags | [] |
| updated_at | 2024-03-22T06:48:18Z |
| virtual_size | Not available |
| visibility | shared |
+------------------+----------------------------------------------------------------------------------+
[root@localhost ~(keystone_admin)]#
列出所有的镜像
[root@localhost ~(keystone_admin)]# glance image-list
+--------------------------------------+-----------+
| ID | Name |
+--------------------------------------+-----------+
| 1f9b092d-68fa-4856-a61c-cf51330789ff | centos7.2 |
| 112198be-3c42-43e8-ba57-5cc87d651876 | cirros |
+--------------------------------------+-----------+
[root@localhost ~(keystone_admin)]#
查看某个镜像详情
名称用不了用ID号
[root@localhost ~(keystone_admin)]# glance image-show centos7.2
HTTP 404 Not Found: No image found with ID centos7.2
[root@localhost ~(keystone_admin)]# glance image-show 1f9b092d-68fa-4856-a61c-cf51330789ff
+------------------+----------------------------------------------------------------------------------+
| Property | Value |
+------------------+----------------------------------------------------------------------------------+
| checksum | ad11feb5af04f08d74ff6f4cb14527fa |
| container_format | bare |
| created_at | 2024-03-22T06:48:07Z |
| disk_format | qcow2 |
| id | 1f9b092d-68fa-4856-a61c-cf51330789ff |
| min_disk | 0 |
| min_ram | 0 |
| name | centos7.2 |
| os_hash_algo | sha512 |
| os_hash_value | 113e5609932b8c161fd4717896c4583f35efeeacc3b8c44380acc4381cc2a1d4121b38a03b03815f |
| | 1868e008e1e30d03b9cf5a3ec6129987f20f33fb77d27bad |
| os_hidden | False |
| owner | 009a94428fb84a0db16aa4a1adab9a35 |
| protected | False |
| size | 1373306880 |
| status | active |
| tags | [] |
| updated_at | 2024-03-22T06:48:18Z |
| virtual_size | Not available |
| visibility | shared |
+------------------+----------------------------------------------------------------------------------+
修改镜像指定大小信息
[root@localhost ~(keystone_admin)]# glance image-update --min-disk=15 1f9b092d-68fa-4856-a61c-cf51330789ff
+------------------+----------------------------------------------------------------------------------+
| Property | Value |
+------------------+----------------------------------------------------------------------------------+
| checksum | ad11feb5af04f08d74ff6f4cb14527fa |
| container_format | bare |
| created_at | 2024-03-22T06:48:07Z |
| disk_format | qcow2 |
| id | 1f9b092d-68fa-4856-a61c-cf51330789ff |
| min_disk | 15 |
| min_ram | 0 |
| name | centos7.2 |
| os_hash_algo | sha512 |
| os_hash_value | 113e5609932b8c161fd4717896c4583f35efeeacc3b8c44380acc4381cc2a1d4121b38a03b03815f |
| | 1868e008e1e30d03b9cf5a3ec6129987f20f33fb77d27bad |
| os_hidden | False |
| owner | 009a94428fb84a0db16aa4a1adab9a35 |
| protected | False |
| size | 1373306880 |
| status | active |
| tags | [] |
| updated_at | 2024-03-22T07:01:37Z |
| virtual_size | Not available |
| visibility | shared |
+------------------+----------------------------------------------------------------------------------+
删除镜像
[root@localhost ~(keystone_admin)]# glance image-list
+--------------------------------------+-----------+
| ID | Name |
+--------------------------------------+-----------+
| 1f9b092d-68fa-4856-a61c-cf51330789ff | centos7.2 |
| 112198be-3c42-43e8-ba57-5cc87d651876 | cirros |
+--------------------------------------+-----------+
[root@localhost ~(keystone_admin)]#
[root@localhost ~(keystone_admin)]# glance image-delete 1f9b092d-68fa-4856-a61c-cf51330789ff
[root@localhost ~(keystone_admin)]# glance image-list
+--------------------------------------+--------+
| ID | Name |
+--------------------------------------+--------+
| 112198be-3c42-43e8-ba57-5cc87d651876 | cirros |
+--------------------------------------+--------+
[root@localhost ~(keystone_admin)]#
openstack 命令执行创建镜像
[root@localhost ~(keystone_admin)]# openstack image create centos7 --disk-format qcow2 --container-format bare --file CentOS7.2.qcow2
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum | ad11feb5af04f08d74ff6f4cb14527fa |
| container_format | bare |
| created_at | 2024-03-22T07:14:10Z |
| disk_format | qcow2 |
| file | /v2/images/1d83e2a5-88c0-40c1-a4f7-2cbb72387b6b/file |
| id | 1d83e2a5-88c0-40c1-a4f7-2cbb72387b6b |
| min_disk | 0 |
| min_ram | 0 |
| name | centos7 |
| owner | 009a94428fb84a0db16aa4a1adab9a35 |
| properties | os_hash_algo='sha512', os_hash_value='113e5609932b8c161fd4717896c4583f35efeeacc3b8c44380acc4381cc2a1d4121b38a03b03815f1868e008e1e30d03b9cf5a3ec6129987f20f33fb77d27bad', os_hidden='False' |
| protected | False |
| schema | /v2/schemas/image |
| size | 1373306880 |
| status | active |
| tags | |
| updated_at | 2024-03-22T07:14:20Z |
| virtual_size | None |
| visibility | shared |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@localhost ~(keystone_admin)]#
openstack 命令修改磁盘大小、查看镜像列表
[root@localhost ~(keystone_admin)]# openstack image set --min-disk=15 centos7
[root@localhost ~(keystone_admin)]# openstack image show centos7
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum | ad11feb5af04f08d74ff6f4cb14527fa |
| container_format | bare |
| created_at | 2024-03-22T07:14:10Z |
| disk_format | qcow2 |
| file | /v2/images/1d83e2a5-88c0-40c1-a4f7-2cbb72387b6b/file |
| id | 1d83e2a5-88c0-40c1-a4f7-2cbb72387b6b |
| min_disk | 15 |
| min_ram | 0 |
| name | centos7 |
| owner | 009a94428fb84a0db16aa4a1adab9a35 |
| properties | os_hash_algo='sha512', os_hash_value='113e5609932b8c161fd4717896c4583f35efeeacc3b8c44380acc4381cc2a1d4121b38a03b03815f1868e008e1e30d03b9cf5a3ec6129987f20f33fb77d27bad', os_hidden='False' |
| protected | False |
| schema | /v2/schemas/image |
| size | 1373306880 |
| status | active |
| tags | |
| updated_at | 2024-03-22T07:15:56Z |
| virtual_size | None |
| visibility | shared |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@localhost ~(keystone_admin)]#
[root@localhost ~(keystone_admin)]# openstack image list
+--------------------------------------+---------+--------+
| ID | Name | Status |
+--------------------------------------+---------+--------+
| 1d83e2a5-88c0-40c1-a4f7-2cbb72387b6b | centos7 | active |
| 112198be-3c42-43e8-ba57-5cc87d651876 | cirros | active |
+--------------------------------------+---------+--------+