nova Evacuate

作用:当一个 node down 掉后,在新的 node 上根据其 DB 中保存的信息重新 build down node 上虚机。这个往往在虚机 HA 方案中用到。它尽可能地将原来的虚机在新的主机上恢复:

  • 虚机的配置:从 DB 中获取,包括 image,block,network 等
  • 虚机的数据:如果使用共享存储,则使用共享存储上的虚机数据;如果不使用共享存储,则无法恢复数据
  • 内存状态:无法恢复

因此,HA 方案中,应该尽可能地将虚机的数据文件放在共享存储上,否则,恢复出来的虚机的价值非常有限。

Nova CLI:usage: nova evacuate [--password <password>] [--on-shared-storage] <server> [<host>]

要求:

(1)必须指定和虚机的 host 不同的 host,否则将报错“The target host can't be the same one”。

(2)虚机的host 必须处于不可用状态即nova compute服务的状态为down,否则将报错 “Compute service of compute2 is still in use.”

(3)可以指定新的 admin password,不指定的话,nova 将生成一个随机密码,如果是共享存储则不能设置新的密码。

(4)参数 on-shared-storage 表示虚机的 instance folder 是不是在共享存储上。如果不设置则让driver自己判断。

主要步骤:

(1)在做完以上各种参数检查后,调用 Conductor 的 方法:

return self.compute_task_api.rebuild_instance(context, instance=instance, new_pass=admin_password, injected_files=None, 

image_ref=None, orig_image_ref=None, orig_sys_metadata=None, bdms=None这些信息会从DB中获取recreate=True

on_shared_storage=on_shared_storage, host=host)

如果 host 为none 的话,conductor 将调用 scheduler 的方法选择一个 host。

(2)接着调用 nova compute 的 rebuild_instance 方法。该方法从系统(DB)中获取已有的数据,然后根据这些已有的 metadata 重新构造domain。“A 'rebuild' effectively purges all existing data from the system and remakes the VM with given 'metadata' and 'personalities'.”

  • 获取 image_ref,再获取 image meta
  • 获取 network_info 并在新的 host 上构造网络
  • 获取 BlockDeviceMappingList
  • 获取 block_device_info

(3)然后调用 virt driver 的 rebuild 方法,但是 libvirt 没有实现该方法,转而调用 _rebuild_default_impl 方法。该方法:

  • 从 volume 端断开其与原来 host 的连接
  • 调用 driver.spawn 方法构造新的 domain,依次创建 image(如果 on_shared_storage = false 的话,则重新下载 image, 构造 instance folder;如果 on_shared_storage = true 的话,则直接使用共享存储上的 instance folder。这也可见使用共享存储的优势),network 和 domain,并设置 domain 的状态和之前一致。

(4)在坏了的 host 被重启后,nova-compute 服务调用 _destroy_evacuated_instances 方法来找到 evacuated instances 并将它们删除:

  • 调用 libvirt 找到该 host 上所有 domains,然后在 nova db 中一一查找其状态,过滤出 “deleted” 为 false 的 domains
            filters = {
                'source_compute': self.host,
                'status': 'accepted',
                'migration_type': 'evacuation',
            }
  • 如果instance.host 不是本机,而且 instance.task_state 不是 { MIGRATING,RESIZE_MIGRATING,RESIZE_MIGRATED,RESIZE_FINISH} 之一,则删除该 domain,以及 network,block device 以及 instance folder。

总之,在使用共享存储的情况下,evacuate 出来的新的 domain 除了临时盘上的数据外,它和之前的 domain 的数据是一样的了,但是内存状态除外。

http://www.cnblogs.com/sammyliu/p/4571209.html

原文地址:https://www.cnblogs.com/allcloud/p/4939425.html