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

先使用cinder创建云硬盘

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

流程如下:

(1)从cinder创建系统盘的流程
cinder.volume.rpcapi.VolumeAPI.create_volume
->cinder.volume.manager.VolumeManager.create_volume
->cinder.volume.flows.manager.create_volume.get_flow
->cinder.volume.flows.manager.create_volume.CreateVolumeFromSpecTask.execute
->cinder.volume.flows.manager.create_volume.CreateVolumeFromSpecTask._create_from_image (_create_raw_volume、_create_from_snapshot)
->cinder.volume.derivers.glusterfs.create_volume (这里是具体驱动的create_volume, VS底层使用glusterfs)
->cinder.volume.derivers.glusterfs._do_create_volume (这里很重要,可能是我们的切入点)
->cinder.volume.derivers.remotefs._create_sparsed_file(class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver)会调到父类的方法)
    ->cinder.volume.flows.manager.create_volume.CreateVolumeFromSpecTask._copy_image_to_volume
->cinder.volume.derivers.remotefs.copy_image_to_volume(class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver)会调到父类的方法)
->cinder.image.image_utils.fetch_to_raw
->cinder.image.image_utils.fetch_to_volume_format
    ->cinder.image.image_utils.fetch (从fetch到fetch再到download和2.6中的流程很像了)
->cinder.image.glance.download(从glance下载镜像到卷)
->cinder.volume.flows.manager.create_volume.CreateVolumeFromSpecTask._handle_bootable_volume_glance_meta (设置为可启动)
创建镜像完毕

(2)nova中从云硬盘启动虚拟机的流程
从云硬盘启动还是从虚拟机启动,在如下地方有差别:
A 在Nova.virt.libvirt.driver._create_image中有差别
nova.api.openstack.compute.servers.Controller.create
->nova.compute.api.API.create
->nova.compute.api.API._create_instance
->nova.comductor.ComputeTaskAPI.build_instances
->nova.conductor. rpcapi.ComputeTaskAPI.build_instances
->nova.conductor. manager.ComputeTaskAPI.build_instances
->nova.compute.rpcapi.ComputeManager.build_and_run_instance
->nova.compute.manager.ComputeManager.build_and_run_instance	
->nova.compute.manager.ComputeManager._locked_do_build_and_run_instance
->nova.compute.manager.ComputeManager._do_build_and_run_instance
->nova.compute.manager.ComputeManager._build_and_run_instance
  ->nova.compute.manager.ComputeManager._build_networks_for_instance //准备网络资源
  ->nova.compute.manager.ComputeManager._prep_block_device //准备块设备
    ->nova.compute.manager.ComputeManager.attach_block_devices 
      ->nova.virt.block_device.DriverImageBlockDevice.attach:volume_api.attach
        ->Nova.volume.API.attach
          ->nova.volume.cinder.API.attach
            -> client = cinderclient(context) ; client.volumes.attach(size, **kwargs)//挂载cinder创建好的卷(云硬盘)
->nova.virt.libvirt.driver.LibvirtDriver.spawn 
->Nova.virt.libvirt.driver._create_image //创建系统盘
这里会检查是从云硬盘启动,还是不从云硬盘启动:
booted_from_volume = self._is_booted_from_volume(
            instance, disk_mapping)
...
if not booted_from_volume:
 ->Nova.virt.libvirt.driver._try_fetch_image_cache
 ->Nova.virt.libvirt.imagebackend.Image.cache
 ->Nova.virt.libvirt.imagebackend.Qcow2.create_image
   ->Nova.virt.libvirt.imagebackend.Qcow2.create_image:prepare_template即fetch_image
     ->Nova.virt.libvirt.utils.fetch_image
       ->Nova.virt.images.fetch_to_raw
         ->Nova.virt.images.fetch  	 		#下载系统镜像到/var/lib/nova/instances/_base/目录
           ->nova.image.glance.GlanceImageService.download
             ->nova.image.glance.GlanceClientWrapper.call
  ->Nova.virt.images.convert_image    #若镜像不是raw格式,且nova.conf中force_raw_images=True,则将backing file强制转换为raw格式
  ->Nova.virt.libvirt.imagebackend.Qcow2.create_image:copy_qcow2_image
  ->nova.virt.libvirt.utils.create_cow_image


你可能感兴趣的:(openstack:nova中“从云硬盘启动”创建虚拟机的流程)