def create_image(context, session, instance, name_label, image_id,
                 image_type):
    """Creates VDI from the image stored in the local cache. If the image
    is not present in the cache, it streams it from glance.

    Returns: A list of dictionaries that describe VDIs
    """
    cache_images = CONF.xenserver.cache_images.lower()

    # Determine if the image is cacheable
    if image_type == ImageType.DISK_ISO:
        cache = False
    elif cache_images == 'all':
        cache = True
    elif cache_images == 'some':
        sys_meta = utils.instance_sys_meta(instance)
        try:
            cache = strutils.bool_from_string(sys_meta['image_cache_in_nova'])
        except __HOLE__:
            cache = False
    elif cache_images == 'none':
        cache = False
    else:
        LOG.warning(_LW("Unrecognized cache_images value '%s', defaulting to"
                        " True"), CONF.xenserver.cache_images)
        cache = True

    # Fetch (and cache) the image
    start_time = timeutils.utcnow()
    if cache:
        downloaded, vdis = _create_cached_image(context, session, instance,
                                                name_label, image_id,
                                                image_type)
    else:
        vdis = _fetch_image(context, session, instance, name_label,
                            image_id, image_type)
        downloaded = True
    duration = timeutils.delta_seconds(start_time, timeutils.utcnow())

    LOG.info(_LI("Image creation data, cacheable: %(cache)s, "
                 "downloaded: %(downloaded)s duration: %(duration).2f secs "
                 "for image %(image_id)s"),
             {'image_id': image_id, 'cache': cache, 'downloaded': downloaded,
              'duration': duration})

    for vdi_type, vdi in six.iteritems(vdis):
        vdi_ref = session.call_xenapi('VDI.get_by_uuid', vdi['uuid'])
        _set_vdi_info(session, vdi_ref, vdi_type, name_label, vdi_type,
                      instance)

    return vdis
dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/virt/xenapi/vm_utils.py/create_image