小菜openstack nova 源码学习之 evacuate

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,


以上皆为个人理解,有不对的地方,还望指点!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值