#NEWLINE# def _fetch_disk_image( context , session , instance , name_label , image_id , image_type ) : #NEWLINE# #INDENT# 'Fetch the image from Glance\n\n    NOTE:\n    Unlike _fetch_vhd_image, this method does not use the Glance\n    plugin; instead, it streams the disks through domU to the VDI\n    directly.\n\n    Returns: A single filename if image_type is KERNEL_RAMDISK\n             A list of dictionaries that describe VDIs, otherwise\n    ' #NEWLINE# image_type_str = ImageType . to_string ( image_type ) #NEWLINE# LOG . debug ( 'Fetching image %(image_id)s, type %(image_type_str)s' , { #NEWLINE# #INDENT# 'image_id' : image_id , #NEWLINE# 'image_type_str' : image_type_str , #NEWLINE# #UNINDENT# } , instance = instance ) #NEWLINE# if ( image_type == ImageType . DISK_ISO ) : #NEWLINE# #INDENT# sr_ref = _safe_find_iso_sr ( session ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sr_ref = safe_find_sr ( session ) #NEWLINE# #UNINDENT# glance_image = image_utils . GlanceImage ( context , image_id ) #NEWLINE# if glance_image . is_raw_tgz ( ) : #NEWLINE# #INDENT# image = image_utils . RawTGZImage ( glance_image ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# image = image_utils . RawImage ( glance_image ) #NEWLINE# #UNINDENT# virtual_size = image . get_size ( ) #NEWLINE# vdi_size = virtual_size #NEWLINE# LOG . debug ( 'Size for image %(image_id)s: %(virtual_size)d' , { #NEWLINE# #INDENT# 'image_id' : image_id , #NEWLINE# 'virtual_size' : virtual_size , #NEWLINE# #UNINDENT# } , instance = instance ) #NEWLINE# if ( image_type == ImageType . DISK ) : #NEWLINE# #INDENT# vdi_size += MBR_SIZE_BYTES #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( image_type in ( ImageType . KERNEL , ImageType . RAMDISK ) ) and ( vdi_size > CONF . xenserver . max_kernel_ramdisk_size ) ) : #NEWLINE# #INDENT# max_size = CONF . xenserver . max_kernel_ramdisk_size #NEWLINE# raise exception . NovaException ( ( _ ( 'Kernel/Ramdisk image is too large: %(vdi_size)d bytes, max %(max_size)d bytes' ) % { #NEWLINE# #INDENT# 'vdi_size' : vdi_size , #NEWLINE# 'max_size' : max_size , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# #UNINDENT# vdi_ref = create_vdi ( session , sr_ref , instance , name_label , image_type_str , vdi_size ) #NEWLINE# try : #NEWLINE# #INDENT# filename = None #NEWLINE# vdi_uuid = session . call_xenapi ( 'VDI.get_uuid' , vdi_ref ) #NEWLINE# with vdi_attached_here ( session , vdi_ref , read_only = False ) as dev : #NEWLINE# #INDENT# _stream_disk ( session , image . stream_to , image_type , virtual_size , dev ) #NEWLINE# #UNINDENT# if ( image_type in ( ImageType . KERNEL , ImageType . RAMDISK ) ) : #NEWLINE# #INDENT# LOG . debug ( 'Copying VDI %s to /boot/guest on dom0' , vdi_ref , instance = instance ) #NEWLINE# args = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# args [ 'vdi-ref' ] = vdi_ref #NEWLINE# args [ 'image-size' ] = str ( vdi_size ) #NEWLINE# if CONF . xenserver . cache_images : #NEWLINE# #INDENT# args [ 'cached-image' ] = image_id #NEWLINE# #UNINDENT# filename = session . call_plugin ( 'kernel' , 'copy_vdi' , args ) #NEWLINE# destroy_vdi ( session , vdi_ref ) #NEWLINE# LOG . debug ( 'Kernel/Ramdisk VDI %s destroyed' , vdi_ref , instance = instance ) #NEWLINE# vdi_role = ImageType . get_role ( image_type ) #NEWLINE# return { #NEWLINE# #INDENT# vdi_role : dict ( uuid = None , file = filename ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# vdi_role = ImageType . get_role ( image_type ) #NEWLINE# return { #NEWLINE# #INDENT# vdi_role : dict ( uuid = vdi_uuid , file = None ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# except ( session . XenAPI . Failure , IOError , OSError ) as e : #NEWLINE# #INDENT# LOG . exception ( _LE ( 'Failed to fetch glance image' ) , instance = instance ) #NEWLINE# e . args = ( e . args + ( [ dict ( type = ImageType . to_string ( image_type ) , uuid = vdi_uuid , file = filename ) ] , ) ) #NEWLINE# raise