当一个虚机不需要使用的时候,可以将其 shelve 起来。该操作会创建该虚机的一个快照并传到 Glance 中,然后在 Hypervisor 上将该虚机删除,从而释放其资源。
其主要过程为:
- destroy 虚机 (virt_dom.destroy())
- snapshot 该 domain
- 如果 CONF.shelved_offload_time == 0 的话,将domain 的各种资源(interface,volume,实例文件等),然后将其undefine (virt_dom.undefine())
其只存在于数据库和 Glance 中。运行 nova list 能看到一条记录:
| 8352e969-0a25-4abf-978f-d9d0ec4de0cd | vm11 | SHELVED_OFFLOADED | - | Shutdown | demo-net2=10.0.10.14; demo-net=10.0.0.41 |
运行 glance image-list 能看到其image:
| 6ed6eb92-ce42-46d1-ab46-259e3e235304 | vm11-shelved | qcow2 | bare | 19988480 | active |
能看到该 image 的 instance 相关的属性:
s1@controller:~$ glance image-show 6ed6eb92-ce42-46d1-ab46-259e3e235304
+---------------------------------------+--------------------------------------+
| Property | Value |
+---------------------------------------+--------------------------------------+
| Property 'base_image_ref' | bb9318db-5554-4857-a309-268c6653b9ff |
| Property 'image_location' | snapshot |
| Property 'image_state' | available |
| Property 'image_type' | snapshot |
| Property 'instance_type_ephemeral_gb' | 1 |
| Property 'instance_type_flavorid' | 129f237e-8825-49fa-b489-0e41fb06b70e |
| Property 'instance_type_id' | 8 |
| Property 'instance_type_memory_mb' | 50 |
| Property 'instance_type_name' | tiny2 |
| Property 'instance_type_root_gb' | 1 |
| Property 'instance_type_rxtx_factor' | 1.0 |
| Property 'instance_type_swap' | 30 |
| Property 'instance_type_vcpus' | 1 |
| Property 'instance_uuid' | 8352e969-0a25-4abf-978f-d9d0ec4de0cd |
| Property 'network_allocated' | True |
| Property 'owner_id' | 74c8ada23a3449f888d9e19b76d13aab |
| Property 'user_id' | bcd37e6272184f34993b4d7686ca4479 |
Unshelve 是 shelve 的反操作。它的主要过程是:
- 从 DB 中获取 network_info 和 block_device_info
- 从 Glance 中获取 image
- 象新建一个虚拟那样 spawn 新的虚机
- 调用 image API 将 image 删除
shelve 对于非后端卷VM,会先根据当前VM信息创建一个镜像待用。
* 之后消息会直接发到VM所在的节点上去。
* 在manager层会根据hypervisor类型,调用具体Driver的关机+快照操作,image_id使用上一步已创建好的镜像。
* 同时在 instance_system_metadata表中添加 shelved_at、shelved_image_id、shelved_host三项内容。
* VM状态变为SHELVED。
* 对于shelve_offload_time =0 时,直接对VM进行shelve_offload,无需定时任务再计时。
对于shelve_offload操作:
l 只有SHELVED状态的VM能够进行shelve-offload操作。
l 且该对外接口需要管理员角色。
l 实质操作仅为调用Driver的删除VM接口,释放hypervisor层面上资源而已。
l VM状态变迁为SHELVED_OFFLOADED。
https://blueprints.launchpad.net/nova/+spec/shelve-instance
https://review.openstack.org/#/c/135387/18