Nova动态迁移流程分析

1. live_migrate API请求处理函数nova/api/openstack/compute/contrib/admin_actions.py@wsgi.action('os-migrateLive') def _migrate_live(self, req, id, body): """Permit admins to (live) migrate
摘要由CSDN通过智能技术生成

作为个人学习笔记分享,有任何问题欢迎交流!

更新记录:

2013.8.2 增加live_migration还是block_migration底层实现的分析

1. live_migrate API请求处理函数

nova/api/openstack/compute/contrib/admin_actions.py

@wsgi.action('os-migrateLive')
    def _migrate_live(self, req, id, body):
        """Permit admins to (live) migrate a server to a new host."""
        context = req.environ["nova.context"]
        authorize(context, 'migrateLive')

        try:
            block_migration = body["os-migrateLive"]["block_migration"]#是否block_migration
            disk_over_commit = body["os-migrateLive"]["disk_over_commit"]#是否disk_over_commit
            host = body["os-migrateLive"]["host"]#目标物理机
        except (TypeError, KeyError):
            msg = _("host and block_migration must be specified.")
            raise exc.HTTPBadRequest(explanation=msg)

#compute_api=nova/compute/api.py:API()
        try:
            instance = self.compute_api.get(context, id)
            self.compute_api.live_migrate(context, instance, block_migration,
                                          disk_over_commit, host)#转到2
        except (exception.ComputeServiceUnavailable,
                exception.InvalidHypervisorType,
                exception.UnableToMigrateToSelf,
                exception.DestinationHypervisorTooOld) as ex:
            raise exc.HTTPBadRequest(explanation=ex.format_message())
        except Exception:
            if host is None:
                msg = _("Live migration of instance %(id)s to another host"
                        " failed") % locals()
            else:
                msg = _("Live migration of instance %(id)s to host %(host)s"
                        " failed") % locals()
            LOG.exception(msg)
            # Return messages from scheduler
            raise exc.HTTPBadRequest(explanation=msg)

        return webob.Response(status_int=202)

2. nova/compute/api.py:API()

 @check_instance_state(vm_state=[vm_states.ACTIVE])
    def live_migrate(self, context, instance, block_migration,
                     disk_over_commit, host_name):
        """Migrate a server lively to a new host."""
        LOG.debug(_("Going to try to live migrate instance to %s"),
                  host_name or "another host", instance=instance)

        instance = self.update(context, instance,
                               task_state=task_states.MIGRATING,
                               expected_task_state=None)

        self.scheduler_rpcapi.live_migration(context, block_migration,
                disk_over_commit, instance, host_name)#调用3

3. nova/scheduler/rpcapi.py:SchedulerAPI()

def live_migration(self, ctxt, block_migration, disk_over_commit,
            instance, dest):
        # NOTE(comstud): Call vs cast so we can get exceptions back, otherwise
        # this call in the scheduler driver doesn't return anything.
        instance_p = jsonutils.to_primitive(instance)
        return self.call(ctxt, self.make_msg('live_migration',
                block_migration=block_migration,
                disk_over_commit=disk_over_commit, instance=instance_p,
                dest=dest))#调用4

4. nova/scheduler/manager.py:SchedulerManager()

def live_migration(self, context, instance,dest,
                       block_migration,disk_over_commit):
       try:
           return self.driver.schedule_live_migration(
                context, instance, dest,
                block_migration,disk_over_commit)#调用4.1
       except (exception.NoValidHost,
               exception.ComputeServiceUnavailable,
               exception.InvalidHypervisorType,
               exception.UnableToMigrateToSelf,
               exception.DestinationHypervisorTooOld,
                exception.InvalidLocalStorage,
                exception.InvalidSharedStorage)as ex:
           request_spec = {'instance_properties': {
                'uuid': instance['uuid'], },
           }
           with excutils.save_and_reraise_exception():
               self._set_vm_state_and_notify('live_migration',
                           dict(vm_state=instance['vm_state'],
                                task_state=None,
                                 expected_task_state=task_states.MIGRATING,),
                                             context, ex, request_spec)
       except Exception as ex:
           with excutils.save_and_reraise_exception():
                self._set_vm_state_and_notify('live_migration',
                                            {'vm_state': vm_states.ERROR},
                                            context, ex, {})

4.1 nova/sc

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值