def fetch_image_stream_optimized(context, instance, session, vm_name, ds_name, vm_folder_ref, res_pool_ref):
 image_ref = instance.image_ref
 LOG.debug("Downloading image file data %(image_ref)s to the ESX as VM named '%(vm_name)s'", {'image_ref': image_ref, 'vm_name': vm_name}, instance=instance)
 metadata = IMAGE_API.get(context, image_ref)
 file_size = int(metadata['size'])
 vm_import_spec = _build_import_spec_for_import_vapp(session, vm_name, ds_name)
 read_iter = IMAGE_API.download(context, image_ref)
 read_handle = rw_handles.ImageReadHandle(read_iter)
 write_handle = rw_handles.VmdkWriteHandle(session, session._host, session._port, res_pool_ref, vm_folder_ref, vm_import_spec, file_size)
 image_transfer(read_handle, write_handle)
 imported_vm_ref = write_handle.get_imported_vm()
 LOG.info(_LI('Downloaded image file data %(image_ref)s'), {'image_ref': instance.image_ref}, instance=instance)
 vmdk = vm_util.get_vmdk_info(session, imported_vm_ref, vm_name)
 session._call_method(session.vim, 'UnregisterVM', imported_vm_ref)
 LOG.info(_LI('The imported VM was unregistered'), instance=instance)
 return vmdk.capacity_in_bytes

def fetch_image_stream_optimized ( context , instance , session , vm_name , ds_name , vm_folder_ref , res_pool_ref ) : image_ref = instance . image_ref LOG . debug ( "Downloading image file data %(image_ref)s to the ESX as VM named '%(vm_name)s'" , { 'image_ref' : image_ref , 'vm_name' : vm_name } , instance = instance ) metadata = IMAGE_API . get ( context , image_ref ) file_size = int ( metadata [ 'size' ] ) vm_import_spec = _build_import_spec_for_import_vapp ( session , vm_name , ds_name ) read_iter = IMAGE_API . download ( context , image_ref ) read_handle = rw_handles . ImageReadHandle ( read_iter ) write_handle = rw_handles . VmdkWriteHandle ( session , session . _host , session . _port , res_pool_ref , vm_folder_ref , vm_import_spec , file_size ) image_transfer ( read_handle , write_handle ) imported_vm_ref = write_handle . get_imported_vm ( ) LOG . info ( _LI ( 'Downloaded image file data %(image_ref)s' ) , { 'image_ref' : instance . image_ref } , instance = instance ) vmdk = vm_util . get_vmdk_info ( session , imported_vm_ref , vm_name ) session . _call_method ( session . vim , 'UnregisterVM' , imported_vm_ref ) LOG . info ( _LI ( 'The imported VM was unregistered' ) , instance = instance ) return vmdk . capacity_in_bytes
fetch image from glance to esx datastore .