nova.api.openstack.compute.evacuate:Evacuate
直接从上路径,进入到evacuate函数
def_evacuate(self, req, id, body):
...
on_shared_storage= self._get_on_shared_storage(req, evacuate_body)
...
进入 _get_on_shared_storage去看看
def_get_on_shared_storage(self, req, evacuate_body):
if api_version_request.is_supported(req, min_version='2.14'):
return None
else:
return strutils.bool_from_string(evacuate_body["onSharedStorage"])
主要是看看版本是否支持,或者返回是否是共享存储的
继续往下看,根据不同的版本,调用不同的获取密码函数
if api_version_request.is_supported(req, min_version='2.14'):
password= self._get_password_v214(req, evacuate_body)
else:
password= self._get_password(req, evacuate_body,
on_shared_storage)
if host is not None: //如果提供了目的主机,这里检测该目的主机是否存在
try:
self.host_api.service_get_by_compute_host(context,host)
//通过 get_instance获取instance信息,判断,实例所在主机是否与提供的目的主机相同
instance= common.get_instance(self.compute_api, context, id)
if instance.host == host:
msg= _("The target host can't be the same one.")
//一切准备就绪以后,开始驱散
try:
self.compute_api.evacuate(context,instance, host,
on_shared_storage,password, force)
//这儿转了很大一圈,最后到
nova.compute.api:evacuate
def evacuate(self, context, instance, host, on_shared_storage,
admin_password=None,force=None):
//首先检测服务状态,如果状态为up,生成错误日志退出
service= objects.Service.get_by_compute_host(context, inst_host)
if self.servicegroup_api.service_is_up(service):
LOG.error(_LE('Instancecompute service state on %s '
' expectedto be down, but it was up.'), inst_host)
//初始化迁移类
migration= objects.Migration(context,
source_compute=instance.host,
source_node=instance.node,
instance_uuid=instance.uuid,
status='accepted',
migration_type='evacuation')
//没怎么弄明白这儿想做什么,因为个人理解,根本没有用到迁移,都是销毁和重建的过程,望大神指点
migration.create()
//在新节点重建虚拟机
return self.compute_task_api.rebuild_instance(context,
以上皆为个人理解,有不对的地方,还望指点!!