Openstack liberty 云主机迁移源码分析之在线迁移3

这是在线迁移 源码分析的第三篇,Openstack liberty 云主机迁移源码分析之在线迁移2中分析了prepare准备阶段nova-compute的处理过程,本文将会分析execute执行阶段的处理过程,下面一起来看具体内容:

execute执行阶段

#`nova/compute/manager.py/ComputeManager._do_live_migration`
def _do_live_migration(self, context, dest, instance, 
                            block_migration,
                            migration, migrate_data):

    #省略prepare准备阶段的代码部分,具体分析请查阅前一篇博文

    """`prepare`准备阶段完成后,返回如下的字典pre_migration_data :
    {'graphics_listen_addrs': {}, 'volume': {},
                    'serial_listen_addr': {}}
    """
    migrate_data['pre_live_migration_result'] = 
                                        pre_migration_data 

    #更新`nova.instance_migrations`数据库,状态改为:running
    if migration:
        migration.status = 'running'
        migration.save()

    migrate_data['migration'] = migration
    try:
        """调用虚拟化驱动(LibvirtDriver)执行迁移

        请看下文的具体分析
        """
        self.driver.live_migration(context, instance, dest,
                               self._post_live_migration,
                               self._rollback_live_migration,
                               block_migration, migrate_data)
    except Exception:
        # Executing live migration
        # live_migration might raises exceptions, but
        # nothing must be recovered in this version.
        LOG.exception(_LE('Live migration failed.'), 
                                            instance=instance)
        #迁移失败,更新`nova.instance_migrations`,状态改为:
        #failed,并上抛异常
        with excutils.save_and_reraise_exception():
            if migration:
                migration.status = 'failed'
                migration.save()

---------------------------------------------------------------
#接上文:`nova/virt/libvirt/driver.py/LibvirtDriver.live_migration`
 def live_migration(self, context, instance, dest,
                       post_method, recover_method, 
                       block_migration=False,
                       migrate_data=None):

    """Spawning live_migration operation for distributing
     high-load.
    """

    # 'dest' will be substituted into 'migration_uri' so ensure
    # it does't contain any characters that could be used to
    # exploit the URI accepted by libivrt
    #校验目的主机名是否合法,只能:单词字符、_、-、.、:
    if not libvirt_utils.is_valid_hostname(dest):
        raise exception.InvalidHostname(hostname=dest)

    #下文分析
    self._live_migration(context, instance, dest,
                             post_method, recover_method, 
                             block_migration,
                             migrate_data)

---------------------------------------------------------------
#接上文:
def _live_migration(self, context, instance, dest, post_method,
                        recover_method, block_migration,
                        migrate_data):
    """Do live migration.

    This fires off a new thread to run the blocking migration
    operation, and then this thread monitors the progress of
    migration and controls its operation
    """

    #通过libvirt获取实例的virDomain对象,然后返回对应的Guest对象
    guest = self._host.get_guest(instance)

    # TODO(sahid): We are converting all calls from a
    # virDomain object to use nova.virt.libvirt.Guest.
    # We should be able to remove dom at the end.
    dom = guest._domain

    #启动新线程执行块迁移,下文具体分析
    opthread = utils.spawn(self._live_migration_operation,
                                     context, instance
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值