Nova动态迁移流程分析

论坛 期权论坛     
选择匿名的用户   2021-5-22 18:54   103   0
<h2></h2>
<h1 style="margin:0px; padding:0px; font-family:Arial; line-height:26px"><span style="font-size:12px"><span style="color:rgb(255,0,0); font-family:新宋体; font-size:13.600000381469727px; line-height:17.987499237060547px; orphans:2; widows:2">作为个人学习笔记分享,有任何问题欢迎交流!</span></span></h1>
<div>
<span style="font-size:12px"><span style="color:rgb(255,0,0); font-family:新宋体; font-size:13.600000381469727px; line-height:17.987499237060547px; orphans:2; widows:2"></span></span>
<p align="left">更新记录:</p> 2013.8.2 增加live_migration还是block_migration底层实现的分析
<br>
</div>
<div>
<br>
</div>
<h2>1. live_migrate API请求处理函数</h2>
<div>
<p align="left"><strong>nova/api/openstack/compute/contrib/admin_actions.py</strong></p>
<pre class="blockcode"><code class="language-python">&#64;wsgi.action(&#39;os-migrateLive&#39;)
    def _migrate_live(self, req, id, body):
        &#34;&#34;&#34;Permit admins to (live) migrate a server to a new host.&#34;&#34;&#34;
        context &#61; req.environ[&#34;nova.context&#34;]
        authorize(context, &#39;migrateLive&#39;)

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

#compute_api&#61;nova/compute/api.py:API()
        try:
            instance &#61; 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&#61;ex.format_message())
        except Exception:
            if host is None:
                msg &#61; _(&#34;Live migration of instance %(id)s to another host&#34;
                        &#34; failed&#34;) % locals()
            else:
                msg &#61; _(&#34;Live migration of instance %(id)s to host %(host)s&#34;
                        &#34; failed&#34;) % locals()
            LOG.exception(msg)
            # Return messages from scheduler
            raise exc.HTTPBadRequest(explanation&#61;msg)

        return webob.Response(status_int&#61;202)
</code></pre>
<h2><span lang="EN-US">2. nova/compute/api.py:API()</span></h2>
<pre class="blockcode"><code class="language-python"> &#64;check_instance_state(vm_state&#61;[vm_states.ACTIVE])
    def live_migrate(self, context, instance, block_migration,
                     disk_over_commit, host_name):
        &#34;&#34;&#34;Migrate a server lively to a new host.&#34;&#34;&#34;
        LOG.debug(_(&#34;Going to try to live migrate instance to %s&#34;),
                  host_name or &#34;another host&#34;, instance&#61;instance)

        instance &#61; self.update(context, instance,
                               task_state&#61;task_states.MIGRATING,
                               expected_task_state&#61;None)

        self.scheduler_rpcapi.live_migration(context, block_migration,
                disk_over_commit, instance, host_name)#调用3
</code></pre>
<h2><span lang="EN-US">3. nova/scheduler/rpcapi.py:SchedulerAPI()</span></h2>
<div>
  <span lang="EN-US"></span>
  <pre class="blockcode"><code class="language-python">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&#39;t return anything.
        instance_p &#61; jsonutils.to_primitive(instance)
        return self.call(ctxt, self.make_msg(&#39;live_migration&#39;,
                block_migration&#61;block_migration,
                disk_over_commit&#61;disk_over_commit, instance&#61;instance_p,
                dest&#61;dest))#调用4</code></pre>
  <h2><span lang="EN-US">4. nova/scheduler/manager.py:SchedulerManager()</span></h2>
</div>
<pre class="blockcode"><code class="language-python">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 &#61; {&#39;instance_properties&#39;: {
                &#39;uuid&#39;: instance[&#39;uuid&#39;], },
           }
           with excutils.save_and_reraise_exception():
               self._set_vm_state_and_notify(&#39;live_migration&#39;,
                           dict(vm_state&#61;instance[&#39;vm_state&#39;],
                                task_state&#61;None,
                                 exp
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP