openstack中的延迟删除、软删除、删除保护

本文详细介绍了OpenStack中的删除机制,包括glance镜像的延迟删除和删除保护,以及nova虚拟机的软删除。在glance中,开启延迟删除后,镜像会被标记为pending_delete,并由scrubber服务在指定时间后进行实际删除;删除保护通过设置镜像的protected属性防止被删除。在nova中,虚拟机的软删除允许在设定的时间间隔内通过API找回已删除的实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

glance镜像的延迟删除
  • 用法
    glance-api.conf中打开延迟删除开关
    1. # Turn on/off delayed delete  
    2. delayed_delete = False  
    3.   
    4. # Delayed delete time in seconds  
    5. scrub_time = 43200  

删除镜像fedora_s2。

[plain] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@controller ~(keystone_admin)]# glance image-list  
  2. +--------------------------------------+-----------+-------------+------------------+-------------+--------+  
  3. | ID                                   | Name      | Disk Format | Container Format | Size        | Status |  
  4. +--------------------------------------+-----------+-------------+------------------+-------------+--------+  
  5. | 42d61acd-1ab3-4a7e-a14e-68ad6ba75215 | centos    | iso         | bare             | 358959104   | active |  
  6. | a7f49865-0388-48f1-a547-f6f23066fb4f | centos_wc | raw         | bare             | 10737418240 | active |  
  7. | f01af3f9-58c3-463d-bf66-fb58825466b4 | fedora_s2 | qcow2       | bare             | 983629824   | active |  
  8. +--------------------------------------+-----------+-------------+------------------+-------------+--------+  
  9. [root@controller ~(keystone_admin)]# glance image-delete fedora_s2  
  10. [root@controller ~(keystone_admin)]# glance image-list  
  11. +--------------------------------------+-----------+-------------+------------------+-------------+--------+  
  12. | ID                                   | Name      | Disk Format | Container Format | Size        | Status |  
  13. +--------------------------------------+-----------+-------------+------------------+-------------+--------+  
  14. | 42d61acd-1ab3-4a7e-a14e-68ad6ba75215 | centos    | iso         | bare             | 358959104   | active |  
  15. | a7f49865-0388-48f1-a547-f6f23066fb4f | centos_wc | raw         | bare             | 10737418240 | active |  
  16. +--------------------------------------+-----------+-------------+------------------+-------------+--------+  

查看数据库信息, fedora_s2的状态为pending_delete。

[python] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. +--------------------------------------+-----------+-----------+----------------+-----------+---------------------+---------------------+---------------------+---------+-------------+------------------+----------------------------------+----------------------------------+----------+---------+-----------+  
  2. | id                                   | name      | size      | status         | is_public | created_at          | updated_at          | deleted_at          | deleted | disk_format | container_format | checksum                         | owner                            | min_disk | min_ram | protected |  
  3. +--------------------------------------+-----------+-----------+----------------+-----------+---------------------+---------------------+---------------------+---------+-------------+------------------+----------------------------------+----------------------------------+----------+---------+-----------+  
  4. | f01af3f9-58c3-463d-bf66-fb58825466b4 | fedora_s2 | 983629824 | pending_delete |         0 | 2014-02-15 15:03:22 | 2014-04-10 17:51:53 | 2014-04-10 17:51:53 |       1 | qcow2       | bare             | c5870838c1c85547d5b85084071db21a | 86196260e1694d0cbb5049cfba3883f8 |       20 |    2048 |         0 |  
  5. +--------------------------------------+-----------+-----------+----------------+-----------+---------------------+---------------------+---------------------+---------+-------------+------------------+----------------------------------+----------------------------------+----------+---------+-----------+  

备注:目前image找回功能的接口还在review中,目前仍不可用。

  • 实现原理
    实现原理很简单。当打开延迟删除开关后,对image的删除不会立刻触发动作,而只是记录的状态为pending_delete和删除时间。
    另外glance有个scrubber的清理服务,会周期性检查pending_delete的image是否到期,到期则进行删除动作。
glance镜像的删除保护
  • 用法
    设置镜像保护是个admin操作,操作方法见如下:
    [plain] view plain copy 在CODE上查看代码片 派生到我的代码片
    1. [root@controller ~(keystone_admin)]# glance image-update --is-protected True centos_wc  
    2. +------------------+--------------------------------------+  
    3. | Property         | Value                                |  
    4. +------------------+--------------------------------------+  
    5. | checksum         | 2f7476ac2fe077979d2f0cda7640d1a8     |  
    6. | container_format | bare                                 |  
    7. | created_at       | 2014-04-03T10:45:19                  |  
    8. | deleted          | False                                |  
    9. | deleted_at       | None                                 |  
    10. | disk_format      | raw                                  |  
    11. | id               | a7f49865-0388-48f1-a547-f6f23066fb4f |  
    12. | is_public        | False                                |  
    13. | min_disk         | 0                                    |  
    14. | min_ram          | 0                                    |  
    15. | name             | centos_wc                            |  
    16. | owner            | 86196260e1694d0cbb5049cfba3883f8     |  
    17. | protected        | True                                 |  
    18. | size             | 10737418240                          |  
    19. | status           | active                               |  
    20. | updated_at       | 2014-04-10T19:00:29                  |  
    21. +------------------+--------------------------------------+  
    22. [root@controller ~(keystone_admin)]# glance image-delete centos_wc  
    23. Request returned failure status.  
    24. 403 Forbidden  
    25. Image is protected  
    26.     (HTTP 403): Unable to delete image centos_wc  

  • 实现原理
    通过image的属性“protected”进行控制。
    删除前检查该属性,未保护则可以删除。保护则不可以删除。
    需要先将属性“protected”修改为“False“才能删除。
nova虚拟机的软删除
  • 用法
    通过nova.conf,设置回收已删除虚拟机的间隔。
    1. # Interval in seconds for reclaiming deleted instances  
    2. # (integer value)  
    3. #reclaim_instance_interval=0  

该值为0,则立刻删除。不为0,则为软删除。
在该时间到达前,可以通过API将虚拟机找回。
周期性任务_reclaim_queued_deletes会定期检查,真正删除已经到达时间的虚拟机。

相关API:

[plain] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # 强制删除(会对虚拟机立刻删除)  
  2. POST v2/​{tenant_id}​/servers/​{server_id}​/action  
  3. {  
  4.     "forceDelete": null  
  5. }  
  6.   
  7. # 找回  
  8. POST v2/​{tenant_id}​/servers/​{server_id}​/action  
  9. {  
  10.     "restore": null  
  11. }  

  • 实现原理
    实现原理比较简单,通过虚拟机数据库中的状态进行软删除控制。
    通过定时任务进行虚拟机的删除。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值