首页服务器Web服务器 OpenStack之虚机热迁移的代码详细解析

OpenStack之虚机热迁移的代码详细解析

话说虚机迁移分为冷迁移以及热迁移,所谓热迁移用度娘的话说即是:热迁移(Live Migration,又叫动态迁移、实时迁移),即虚机保存/恢复(Save/Restore):将整个虚拟机的运行状态完整保存…

话说虚机迁移分为冷迁移以及热迁移,所谓热迁移用度娘的话说即是:热迁移(Live Migration,又叫动态迁移、实时迁移),即虚机保存/恢复(Save/Restore):将整个虚拟机的运行状态完整保存下来,同时可以快速的恢复到原有硬件平台甚至是不同硬件平台上。恢复以后,虚机仍旧平滑运行,用户不会察觉到任何差异。OpenStack的虚机迁移是基于Libvirt实现的,下面来看看Openstack虚机热迁移的具体代码实现。

首先,由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"]      disk_over_commit = body["os-migrateLive"]["disk_over_commit"]      host = body["os-migrateLive"]["host"]    except (TypeError, KeyError):      msg = _("host, block_migration and disk_over_commit must "          "be specified for live migration.")      raise exc.HTTPBadRequest(explanation=msg)    try:      block_migration = strutils.bool_from_string(block_migration,                            strict=True)      disk_over_commit = strutils.bool_from_string(disk_over_commit,                             strict=True)    except ValueError as err:      raise exc.HTTPBadRequest(explanation=str(err))    try:      instance = self.compute_api.get(context, id, want_objects=True)      self.compute_api.live_migrate(context, instance, block_migration,                     disk_over_commit, host)    except (exception.ComputeServiceUnavailable,        exception.InvalidHypervisorType,        exception.UnableToMigrateToSelf,        exception.DestinationHypervisorTooOld,        exception.NoValidHost,        exception.InvalidLocalStorage,        exception.InvalidSharedStorage,        exception.MigrationPreCheckError) as ex:      raise exc.HTTPBadRequest(explanation=ex.format_message())    except exception.InstanceNotFound as e:      raise exc.HTTPNotFound(explanation=e.format_message())    except exception.InstanceInvalidState as state_error:      common.raise_http_conflict_for_instance_invalid_state(state_error,          'os-migrateLive')    except Exception:      if host is None:        msg = _("Live migration of instance %s to another host "            "failed") % id      else:        msg = _("Live migration of instance %(id)s to host %(host)s "            "failed") % {'id': id, 'host': host}      LOG.exception(msg)      # Return messages from scheduler      raise exc.HTTPBadRequest(explanation=msg)    return webob.Response(status_int=202)
本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/fwq/web/5367.html
上一篇理解Docker(2):Docker 镜像详细介绍
下一篇 docker 的java编译环境构建详细介绍
admin

作者: admin

这里可以再内容模板定义一些文字和说明,也可以调用对应作者的简介!或者做一些网站的描述之类的文字或者HTML!

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

    工作时间:周一至周五,9:00-17:30,节假日休息

    关注微信
    微信扫一扫关注我们

    微信扫一扫关注我们

    关注微博
    返回顶部