def _fetch_vhd_image(context, session, instance, image_id):
    LOG.debug("Asking xapi to fetch vhd image %s", image_id,
              instance=instance)

    handler = _choose_download_handler(context, instance)

    try:
        vdis = handler.download_image(context, session, instance, image_id)
    except Exception:
        default_handler = _default_download_handler()

        # Using type() instead of isinstance() so instance of subclass doesn't
        # test as equivalent
        if type(handler) == type(default_handler):
            raise

        LOG.exception(_LE("Download handler '%(handler)s' raised an"
                          " exception, falling back to default handler"
                          " '%(default_handler)s'"),
                      {'handler': handler,
                       'default_handler': default_handler})

        vdis = default_handler.download_image(
                context, session, instance, image_id)

    # Ensure we can see the import VHDs as VDIs
    scan_default_sr(session)

    vdi_uuid = vdis['root']['uuid']
    try:
        _check_vdi_size(context, session, instance, vdi_uuid)
    except Exception:
        with excutils.save_and_reraise_exception():
            msg = "Error while checking vdi size"
            LOG.debug(msg, instance=instance, exc_info=True)
            for vdi in vdis.values():
                vdi_uuid = vdi['uuid']
                vdi_ref = session.call_xenapi('VDI.get_by_uuid', vdi_uuid)
                safe_destroy_vdis(session, [vdi_ref])

    return vdis
Tell glance to download an image and put the VHDs into the SR
dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/virt/xenapi/vm_utils.py/_fetch_vhd_image