openstack:nova中“从云硬盘启动”创建虚拟机的流程

来源:互联网 发布:淘宝可以用黑体吗 编辑:程序博客网 时间:2024/05/16 14:11

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


先使用cinder创建云硬盘

然后在nova中创建示例的时候,会先在_prep_block_device中挂载cinder中创建的卷,然后创建虚拟机

流程如下:

[python] view plaincopy
  1. 1)从cinder创建系统盘的流程  
  2. cinder.volume.rpcapi.VolumeAPI.create_volume  
  3. ->cinder.volume.manager.VolumeManager.create_volume  
  4. ->cinder.volume.flows.manager.create_volume.get_flow  
  5. ->cinder.volume.flows.manager.create_volume.CreateVolumeFromSpecTask.execute  
  6. ->cinder.volume.flows.manager.create_volume.CreateVolumeFromSpecTask._create_from_image (_create_raw_volume、_create_from_snapshot)  
  7. ->cinder.volume.derivers.glusterfs.create_volume (这里是具体驱动的create_volume, VS底层使用glusterfs)  
  8. ->cinder.volume.derivers.glusterfs._do_create_volume (这里很重要,可能是我们的切入点)  
  9. ->cinder.volume.derivers.remotefs._create_sparsed_file(class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver)会调到父类的方法)  
  10.     ->cinder.volume.flows.manager.create_volume.CreateVolumeFromSpecTask._copy_image_to_volume  
  11. ->cinder.volume.derivers.remotefs.copy_image_to_volume(class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver)会调到父类的方法)  
  12. ->cinder.image.image_utils.fetch_to_raw  
  13. ->cinder.image.image_utils.fetch_to_volume_format  
  14.     ->cinder.image.image_utils.fetch (从fetch到fetch再到download和2.6中的流程很像了)  
  15. ->cinder.image.glance.download(从glance下载镜像到卷)  
  16. ->cinder.volume.flows.manager.create_volume.CreateVolumeFromSpecTask._handle_bootable_volume_glance_meta (设置为可启动)  
  17. 创建镜像完毕  
  18.   
  19. 2)nova中从云硬盘启动虚拟机的流程  
  20. 从云硬盘启动还是从虚拟机启动,在如下地方有差别:  
  21. A 在Nova.virt.libvirt.driver._create_image中有差别  
  22. nova.api.openstack.compute.servers.Controller.create  
  23. ->nova.compute.api.API.create  
  24. ->nova.compute.api.API._create_instance  
  25. ->nova.comductor.ComputeTaskAPI.build_instances  
  26. ->nova.conductor. rpcapi.ComputeTaskAPI.build_instances  
  27. ->nova.conductor. manager.ComputeTaskAPI.build_instances  
  28. ->nova.compute.rpcapi.ComputeManager.build_and_run_instance  
  29. ->nova.compute.manager.ComputeManager.build_and_run_instance   
  30. ->nova.compute.manager.ComputeManager._locked_do_build_and_run_instance  
  31. ->nova.compute.manager.ComputeManager._do_build_and_run_instance  
  32. ->nova.compute.manager.ComputeManager._build_and_run_instance  
  33.   ->nova.compute.manager.ComputeManager._build_networks_for_instance //准备网络资源  
  34.   ->nova.compute.manager.ComputeManager._prep_block_device //准备块设备  
  35.     ->nova.compute.manager.ComputeManager.attach_block_devices   
  36.       ->nova.virt.block_device.DriverImageBlockDevice.attach:volume_api.attach  
  37.         ->Nova.volume.API.attach  
  38.           ->nova.volume.cinder.API.attach  
  39.             -> client = cinderclient(context) ; client.volumes.attach(size, **kwargs)//挂载cinder创建好的卷(云硬盘)  
  40. ->nova.virt.libvirt.driver.LibvirtDriver.spawn   
  41. ->Nova.virt.libvirt.driver._create_image //创建系统盘  
  42. 这里会检查是从云硬盘启动,还是不从云硬盘启动:  
  43. booted_from_volume = self._is_booted_from_volume(  
  44.             instance, disk_mapping)  
  45. ...  
  46. if not booted_from_volume:  
  47.  ->Nova.virt.libvirt.driver._try_fetch_image_cache  
  48.  ->Nova.virt.libvirt.imagebackend.Image.cache  
  49.  ->Nova.virt.libvirt.imagebackend.Qcow2.create_image  
  50.    ->Nova.virt.libvirt.imagebackend.Qcow2.create_image:prepare_template即fetch_image  
  51.      ->Nova.virt.libvirt.utils.fetch_image  
  52.        ->Nova.virt.images.fetch_to_raw  
  53.          ->Nova.virt.images.fetch            #下载系统镜像到/var/lib/nova/instances/_base/目录  
  54.            ->nova.image.glance.GlanceImageService.download  
  55.              ->nova.image.glance.GlanceClientWrapper.call  
  56.   ->Nova.virt.images.convert_image    #若镜像不是raw格式,且nova.conf中force_raw_images=True,则将backing file强制转换为raw格式  
  57.   ->Nova.virt.libvirt.imagebackend.Qcow2.create_image:copy_qcow2_image  
  58.   ->nova.virt.libvirt.utils.create_cow_image  

0 0
原创粉丝点击