热门标签 | HotTags
当前位置:  开发笔记 > 开发工具 > 正文

openstack.nova.manager创建虚拟机流程(run_instance)

本文主要分析nova中虚拟机的启动过程,着重介绍此过程的状态改变和响应的操作。代码整理自nova/compute/manager.py代码的顺序有改动,只是为了方便查看,完整的代码可以参考:https://github.com/openstack/nova/blob/master/nova/compute/manage

本文主要分析nova中虚拟机的启动过程,着重介绍此过程的状态改变和响应的操作。

代码整理自 nova/compute/manager.py 代码的顺序有改动,只是为了方便查看,完整的代码可以参考:https://github.com/openstack/nova/blob /master/nova/compute/manager.py

虚拟机的创建流程为3步走:

向nova-network申请IP

向nova-volumn申请block_device

向driver申请创建虚拟机

同时伴随整个过程,虚拟机的vm_state始终是building,但是task_state将会变化三次:

networking

block_device_mapping

spawing

最后,虚拟机的vm_state变成active.

def run_instance(self):
    building proccess:
        None
        +
        networking
        |  network_api.allocate_for_instance (nova-network)
        +
        block_device_mapping
        |  setup_block_device_mapping (nova-volumn)
        +
        spawing
        |  driver.spawn (nova-compute.driver)
        +
        Active
    """
    instance = self.db.instance_get_by_uuid(context, instance_uuid)
    self._check_instance_not_already_created(context, instance)
    image_meta = self._check_image_size(context, instance)
    # VM_state = building
    # task_state = None
    self._instance_update(context, instance['uuid'],
                        host=self.host, launched_on=self.host,
                        vm_state=vm_states.BUILDING,
                        task_state=None)
    # VM_state = building
    # task_state = networking
    self._instance_update(context, instance['uuid'],
                        vm_state=vm_states.BUILDING,
                        task_state=task_states.NETWORKING)
    network_info = self.network_api.allocate_for_instance(
                        context, instance, vpn=is_vpn,
                        requested_networks=requested_networks)
    # VM_state = building
    # task_statue = block_device_mapping
    self._instance_update(context, instance['uuid'],
                        vm_state=vm_states.BUILDING,
                        task_state=task_states.BLOCK_DEVICE_MAPPING)
    self._setup_block_device_mapping(context, instance)
    # VM_state = building
    # task_statue = spawing
    self._instance_update(context, instance['uuid'],
                        vm_state=vm_states.BUILDING,
                        task_state=task_states.SPAWNING)
    instance['injected_files'] = injected_files
    instance['admin_pass'] = admin_pass
    self.driver.spawn(context, instance, image_meta,
                        self._legacy_nw_info(network_info), block_device_info)
    # VM_state = active
    # task_statue = None
    self._instance_update(context, instance['uuid'],
                        power_state=current_power_state,
                        vm_state=vm_states.ACTIVE,
                        task_state=None,
                        launched_at=utils.utcnow())

下面上思维图,希望大家能多多交流!


推荐阅读
author-avatar
手机用户2502853373
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有