@
Glance映象服務介紹
Glance是OpenStack映象服務,用來註冊、登陸和檢索虛擬機器映象。Glance服務提供了一個REST API,使讀者能夠查詢虛擬機器映象後設資料和檢索的實際映象。通過映象服務提供的虛擬機器映象可以儲存在不同的位置,從簡單的檔案系統物件儲存到類似OpenStack物件儲存系統。
建立映象
CirrOS是一個極小的雲作業系統,可以使用這個小的作業系統來進行Glance服務元件的操作練習。將提供的cirros-0.3.4-x86_64-disk.img映象上傳到controller節點的root目錄下面
[root@controller ~]# ls
cirros-0.3.4-x86_64-disk.img
將映象上傳至controller節點後,通過file命令檢視映象檔案資訊
[root@controller ~]# file cirros-0.3.4-x86_64-disk.img
cirros-0.3.4-x86_64-disk.img: QEMU QCOW Image (v2), 41126400 bytes
通過命令建立映象,命令的格式如下:
[root@controller images]# 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]
#引數說明
--disk-format:映象格式
--container-format: 映象在其他專案中可見性
--progress: 顯示上傳映象的進度
--file:選擇本地映象檔案
--name:上傳後映象的名稱
使用映象cirros-0.3.4-x86_64-disk.img通過命令上傳映象至OpenStack中
[root@controller ~]# glance image-create --name cirros-0.3.4 --disk-format qcow2 --container-format bare --progress < cirros-0.3.4-x86_64-disk.img
[=============================>] 100%
+------------------+--------------------------------------------------------------------+
| Property | Value |
+------------------+--------------------------------------------------------------------+
| checksum | f8ab98ff5e73ebab884d80c9dc9c7290 |
| container_format | bare |
| created_at | 2022-02-10T03:15:29Z |
| disk_format | qcow2 |
| id | 32a2513c-e5ba-438b-a5ee-63c35c03b284 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros-0.3.4 |
| os_hash_algo | sha512 |
| os_hash_value | f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f9
19ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232 |
| os_hidden | False |
| owner | 1776912d52a7444d8b2d09eb86e8d1d9 |
| protected | False |
| size | 13267968 |
| status | active |
| tags | [] |
| updated_at | 2022-02-10T03:15:29Z |
| virtual_size | Not available |
| visibility | shared |
+------------------+--------------------------------------------------------------------+
檢視映象
通過命令可以在OpenStack平臺中檢視當前glance中所上傳的映象名稱
[root@controller ~]# glance image-list
+--------------------------------------+--------------+
| ID | Name |
+--------------------------------------+--------------+
| 32a2513c-e5ba-438b-a5ee-63c35c03b284 | cirros-0.3.4 |
+--------------------------------------+--------------+
也可以使用命令檢視映象的詳細資訊
[root@controller ~]# glance image-show 32a2513c-e5ba-438b-a5ee-63c35c03b284
+------------------+--------------------------------------------------------------------+
| Property | Value |
+------------------+------------------------------------------------------------------ -+
| checksum | f8ab98ff5e73ebab884d80c9dc9c7290 |
| container_format | bare |
| created_at | 2022-02-10T03:15:29Z |
| disk_format | qcow2 |
| id | 32a2513c-e5ba-438b-a5ee-63c35c03b284 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros-0.3.4 |
| os_hash_algo | sha512 |
| os_hash_value | f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f9
19ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232 |
| os_hidden | False |
| owner | 1776912d52a7444d8b2d09eb86e8d1d9 |
| protected | False |
| size | 13267968 |
| status | active |
| tags | [] |
| updated_at | 2022-02-10T03:15:29Z |
| virtual_size | Not available |
| visibility | shared |
+------------------+--------------------------------------------------------------------+
修改映象
可以使用glance image-update更新映象資訊,命令的格式如下
[root@controller images]# glance help image-update
usage: glance image-update [--architecture <ARCHITECTURE>]
[--protected [True|False]] [--name <NAME>]
[--instance-uuid <INSTANCE_UUID>]
[--min-disk <MIN_DISK>] [--visibility <VISIBILITY>]
[--kernel-id <KERNEL_ID>]
[--os-version <OS_VERSION>]
[--disk-format <DISK_FORMAT>]
[--os-distro <OS_DISTRO>] [--owner <OWNER>]
[--ramdisk-id <RAMDISK_ID>] [--min-ram <MIN_RAM>]
[--container-format <CONTAINER_FORMAT>]
[--property <key=value>] [--remove-property key]
<IMAGE_ID>
#引數說明
--min-disk:映象啟動最小硬碟大小
--name:映象名稱
--disk-format:映象格式
--min-ram:映象啟動最小記憶體大小
--container-format:映象在專案中可見性
如果需要改變映象啟動硬碟最低要求值(min-disk)1G,min-disk預設單位為G。使用glance image-update更新映象資訊操作如下
[root@controller ~]# glance image-update --min-disk=1 32a2513c-e5ba-438b-a5ee-63c35c03b284
+------------------+--------------------------------------------------------------------+
| Property | Value |
+------------------+--------------------------------------------------------------------+
| checksum | f8ab98ff5e73ebab884d80c9dc9c7290 |
| container_format | bare |
| created_at | 2022-02-10T03:15:29Z |
| disk_format | qcow2 |
| id | 32a2513c-e5ba-438b-a5ee-63c35c03b284 |
| min_disk | 1 |
| min_ram | 0 |
| name | cirros-0.3.4 |
| os_hash_algo | sha512 |
| os_hash_value | f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f9
19ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232 |
| os_hidden | False |
| owner | 1776912d52a7444d8b2d09eb86e8d1d9 |
| protected | False |
| size | 13267968 |
| status | active |
| tags | [] |
| updated_at | 2022-02-10T03:16:59Z |
| virtual_size | Not available |
| visibility | shared |
+------------------+--------------------------------------------------------------------+
也可以使用命令更新映象啟動記憶體最低要求值(min-ram)為1G,min-ram預設單位為M。使用glance image-update更新映象資訊操作如下:
[root@controller ~]# glance image-update --min-ram=1024 32a2513c-e5ba-438b-a5ee-63c35c03b284
+------------------+--------------------------------------------------------------------+
| Property | Value |
+------------------+--------------------------------------------------------------------+
| checksum | f8ab98ff5e73ebab884d80c9dc9c7290 |
| container_format | bare |
| created_at | 2022-02-10T03:15:29Z |
| disk_format | qcow2 |
| id | 32a2513c-e5ba-438b-a5ee-63c35c03b284 |
| min_disk | 1 |
| min_ram | 1024 |
| name | cirros-0.3.4 |
| os_hash_algo | sha512 |
| os_hash_value | f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f9
19ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232 |
| os_hidden | False |
| owner | 1776912d52a7444d8b2d09eb86e8d1d9 |
| protected | False |
| size | 13267968 |
| status | active |
| tags | [] |
| updated_at | 2022-02-10T03:17:21Z |
| virtual_size | Not available |
| visibility | shared |
+------------------+--------------------------------------------------------------------+
刪除映象
可以使用glance image-delete刪除上傳至OpenStack平臺中的映象,只需要在命令後跟上映象ID即可
[root@controller images]# glance image-delete 32a2513c-e5ba-438b-a5ee-63c35c03b284
[root@controller images]# glance image-list
+--------------------------------------+------------------------------+
| ID | Name |
+--------------------------------------+------------------------------+
+--------------------------------------+------------------------------+