def _generate_disk(session, instance, vm_ref, userdevice, name_label,
                   disk_type, size_mb, fs_type, fs_label=None):
    # 1. Create VDI
    sr_ref = safe_find_sr(session)
    ONE_MEG = units.Mi
    virtual_size = size_mb * ONE_MEG
    vdi_ref = create_vdi(session, sr_ref, instance, name_label, disk_type,
                         virtual_size)

    try:
        # 2. Attach VDI to compute worker (VBD hotplug)
        with vdi_attached_here(session, vdi_ref, read_only=False) as dev:
            # 3. Create partition
            partition_start = "2048s"
            partition_end = "-0"

            partition_path = _make_partition(session, dev,
                                             partition_start, partition_end)

            if fs_type is not None:
                utils.mkfs(fs_type, partition_path, fs_label,
                           run_as_root=True)

        # 4. Create VBD between instance VM and VDI
        if vm_ref:
            create_vbd(session, vm_ref, vdi_ref, userdevice, bootable=False)
    except Exception:
        with excutils.save_and_reraise_exception():
            msg = "Error while generating disk number: %s" % userdevice
            LOG.debug(msg, instance=instance, exc_info=True)
            safe_destroy_vdis(session, [vdi_ref])

    return vdi_ref
Returns the index of the specified image.
dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/virt/xenapi/vm_utils.py/_generate_disk--crossover with--dataset/ETHPy150Open enthought/pyface/pyface/wx/image_list.py/ImageList.GetIndex