Gather the disk profile from the config or apply the default based
    on the active hypervisor

    This is the ``default`` profile for KVM/QEMU, which can be
    overridden in the configuration:

    .. code-block:: yaml

        virt:
          disk:
            default:
              - system:
                  size: 8192
                  format: qcow2
                  model: virtio

    Example profile for KVM/QEMU with two disks, first is created
    from specified image, the second is empty:

    .. code-block:: yaml

        virt:
          disk:
            two_disks:
              - system:
                  size: 8192
                  format: qcow2
                  model: virtio
                  image: http://path/to/image.qcow2
              - lvm:
                  size: 32768
                  format: qcow2
                  model: virtio

    The ``format`` and ``model`` parameters are optional, and will
    default to whatever is best suitable for the active hypervisor.

def _disk_profile(profile, hypervisor, disks=None, vm_name=None, image=None, pool=None, **kwargs):
    '''
    Gather the disk profile from the config or apply the default based
    on the active hypervisor

    This is the ``default`` profile for KVM/QEMU, which can be
    overridden in the configuration:

    .. code-block:: yaml

        virt:
          disk:
            default:
              - system:
                  size: 8192
                  format: qcow2
                  model: virtio

    Example profile for KVM/QEMU with two disks, first is created
    from specified image, the second is empty:

    .. code-block:: yaml

        virt:
          disk:
            two_disks:
              - system:
                  size: 8192
                  format: qcow2
                  model: virtio
                  image: http://path/to/image.qcow2
              - lvm:
                  size: 32768
                  format: qcow2
                  model: virtio

    The ``format`` and ``model`` parameters are optional, and will
    default to whatever is best suitable for the active hypervisor.
    '''
    default = [{'system':
                {'size': 8192}}]
    if hypervisor == 'vmware':
        overlay = {'format': 'vmdk',
                   'model': 'scsi',
                   'device': 'disk',
                   'pool': '[{0}] '.format(pool if pool else '0')}
    elif hypervisor in ['qemu', 'kvm']:
        overlay = {'format': 'qcow2',
                   'device': 'disk',
                   'model': 'virtio'}
    elif hypervisor in ['bhyve']:
        overlay = {'format': 'raw',
                   'device': 'disk',
                   'model': 'virtio',
                   'sparse_volume': False}
    elif hypervisor == 'xen':
        overlay = {'format': 'qcow2',
                   'device': 'disk',
                   'model': 'xen'}
    else:
        overlay = {}

    # Get the disks from the profile
    disklist = []
    if profile:
        disklist = copy.deepcopy(
            __salt__['config.get']('virt:disk', {}).get(profile, default))

        # Transform the list to remove one level of dictionnary and add the name as a property
        disklist = [dict(d, name=name) for disk in disklist for name, d in disk.items()]

        # Add the image to the first disk if there is one
        if image:
            # If image is specified in module arguments, then it will be used
            # for the first disk instead of the image from the disk profile
            log.debug('%s image from module arguments will be used for disk "%s"'
                      ' instead of %s', image, disklist[0]['name'], disklist[0].get('image', ""))
            disklist[0]['image'] = image

    # Merge with the user-provided disks definitions
    if disks:
        for udisk in disks:
            if 'name' in udisk:
                found = [disk for disk in disklist if udisk['name'] == disk['name']]
                if found:
                    found[0].update(udisk)
                else:
                    disklist.append(udisk)

    for disk in disklist:
        # Add the missing properties that have defaults
        for key, val in six.iteritems(overlay):
            if key not in disk:
                disk[key] = val

        # We may have an already computed source_file (i.e. image not created by our module)
        if 'source_file' in disk and disk['source_file']:
            disk['filename'] = os.path.basename(disk['source_file'])
        elif 'source_file' not in disk:
            _fill_disk_filename(vm_name, disk, hypervisor, **kwargs)

    return disklist