openstack:nova中“从镜像启动(创建一个新卷)”创建虚拟机的流程

原文网址:http://blog.csdn.net/xiangpingli/article/details/47912777

nova还有一种启动方式:“从镜像启动(创建一个新卷)”

这个流程中,nova会在_prep_block_device中的attach_block_device去调用cinder的create创建一个卷

然后会在_prep_block_device中的attach_block_device去调用cinder的attach挂载这个卷

然后才去spawn,孵化虚拟机,在spawn中会调用_create_image来创建镜像,这里创建镜像不是创建卷,卷是在_prep_block_device创建好的,除非是“从镜像启动”才会在

_create_image创建卷。

下面看下nova中“从镜像启动(创建一个新卷)”创建虚拟机的流程:

[python]  view plain copy
  1. nova.api.openstack.compute.servers.Controller.create  
  2. ->nova.compute.api.API.create  
  3. ->nova.compute.api.API._create_instance  
  4. ->nova.comductor.ComputeTaskAPI.build_instances  
  5. ->nova.conductor. rpcapi.ComputeTaskAPI.build_instances  
  6. ->nova.conductor. manager.ComputeTaskAPI.build_instances  
  7. ->nova.compute.rpcapi.ComputeManager.build_and_run_instance  
  8. ->nova.compute.manager.ComputeManager._do_build_and_run_instance  
  9. ->nova.compute.manager.ComputeManager._build_and_run_instance //直到这里,流程仍与前两种创建虚拟机的情况相同,看看最终是哪里有差别  
  10. ->nova.compute.manager.ComputeManager._build_resources  
  11.   ->nova.compute.manager.ComputeManager._build_networks_for_instance //准备网络资源  
  12.   ->nova.compute.manager.ComputeManager._prep_block_device //准备块设备  
  13.    ->nova.compute.manager.ComputeManager.attach_block_devices   
  14.     ->nova.virt.block_device.attach_block_devices   
  15.       ->nova.virt.block_device.DriverImageBlockDevice.attach  
  16.         ->nova.virt.driver.create  
  17.          ->nova.virt.libvrit.driver.create 创建一个新卷  
  18.       ->nova.virt.block_device.DriverVolumeBlockDevice.attach (DriverVolumeBlockDevice是DriverImageBlockDevice的父类)  
  19.         ->nova.virt.driver.attach  
  20.           ->nova.virt.libvirt.driver.attach 挂载这个卷    
  21. ->nova.virt.libvirt.driver.LibvirtDriver.spawn   
  22. //再回过头来梳理下spawn,是不是这时候块设备都有了呢?之前的流程是不是有点问题?  
  23. //是不是块设备在_prep_block_device都建好了,后面只是向里面填不同的内容?  
  24. //那么spawn中的_create_image 又做了什么呢?上面的_prep_block_device和spawn中的_create_image分别做什么?看起来都像建卷?  
  25. //事实上,是一个建卷(_prep_block_device只是块设备,里面没有东西)而一个是在卷上组织镜像(_create_image之前卷已经存在,这里只是组织镜像)  
  26. //另外考虑分支情况:(1)如果卷存在_prep_block_device流程怎么走?(2)如果从云硬盘启动_create_image流程怎么走  
  27. //也就是说把分支情况也要考虑好  
  28. 接上面:  
  29. ->nova.virt.libvirt.driver.LibvirtDriver.spawn   
  30. ->Nova.virt.libvirt.driver._create_image //组织镜像  
  31. 这里会检查是从云硬盘启动,还是不从云硬盘启动:  
  32. booted_from_volume = self._is_booted_from_volume(  
  33.             instance, disk_mapping)  
  34. ...  
  35. if not booted_from_volume:  
  36.  ->Nova.virt.libvirt.driver._try_fetch_image_cache  
  37.  ->Nova.virt.libvirt.imagebackend.Image.cache  
  38.  ->Nova.virt.libvirt.imagebackend.Qcow2.create_image  
  39.    ->Nova.virt.libvirt.imagebackend.Qcow2.create_image:prepare_template即fetch_image  
  40.      ->Nova.virt.libvirt.utils.fetch_image  
  41.        ->Nova.virt.images.fetch_to_raw  
  42.          ->Nova.virt.images.fetch            #下载系统镜像到/var/lib/nova/instances/_base/目录  
  43.            ->nova.image.glance.GlanceImageService.download  
  44.              ->nova.image.glance.GlanceClientWrapper.call  
  45.   ->Nova.virt.images.convert_image    #若镜像不是raw格式,且nova.conf中force_raw_images=True,则将backing file强制转换为raw格式  
  46.   ->Nova.virt.libvirt.imagebackend.Qcow2.create_image:copy_qcow2_image  
  47.   ->nova.virt.libvirt.utils.create_cow_image  

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值