@classmethod
    def determine_disk_image_type(cls, instance, context):
        """Disk Image Types are used to determine where the kernel will reside
        within an image. To figure out which type we're dealing with, we use
        the following rules:

        1. If we're using Glance, we can use the image_type field to
           determine the image_type

        2. If we're not using Glance, then we need to deduce this based on
           whether a kernel_id is specified.
        """
        def log_disk_format(image_type):
            pretty_format = {ImageType.KERNEL: 'KERNEL',
                             ImageType.RAMDISK: 'RAMDISK',
                             ImageType.DISK: 'DISK',
                             ImageType.DISK_RAW: 'DISK_RAW',
                             ImageType.DISK_VHD: 'DISK_VHD',
                             ImageType.DISK_ISO: 'DISK_ISO'}
            disk_format = pretty_format[image_type]
            image_ref = instance.image_ref
            instance_id = instance.id
            LOG.debug(_("Detected %(disk_format)s format for image "
                        "%(image_ref)s, instance %(instance_id)s") % locals())

        def determine_from_glance():
            glance_disk_format2nova_type = {
                'ami': ImageType.DISK,
                'aki': ImageType.KERNEL,
                'ari': ImageType.RAMDISK,
                'raw': ImageType.DISK_RAW,
                'vhd': ImageType.DISK_VHD,
                'iso': ImageType.DISK_ISO}
            image_ref = instance.image_ref
            glance_client, image_id = glance.get_glance_client(context,
                                                               image_ref)
            meta = glance_client.get_image_meta(image_id)
            disk_format = meta['disk_format']
            try:
                return glance_disk_format2nova_type[disk_format]
            except __HOLE__:
                raise exception.InvalidDiskFormat(disk_format=disk_format)

        def determine_from_instance():
            if instance.kernel_id:
                return ImageType.DISK
            else:
                return ImageType.DISK_RAW

        image_type = determine_from_glance()

        log_disk_format(image_type)
        return image_type
dataset/ETHPy150Open nii-cloud/dodai-compute/nova/virt/xenapi/vm_utils.py/VMHelper.determine_disk_image_type