Sets the disk to be saved in the given image.

    .. versionadded:: 2016.3.0

    name
        The name of the VM containing the disk to save.

    disk_id
        The ID of the disk to save.

    image_name
        The name of the new image where the disk will be saved.

    image_type
        The type for the new image. If not set, then the default ``ONED`` Configuration
        will be used. Other valid types include: OS, CDROM, DATABLOCK, KERNEL, RAMDISK,
        and CONTEXT.

    snapshot_id
        The ID of the snapshot to export. If not set, the current image state will be
        used.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a vm_disk_save my-vm disk_id=1 image_name=my-new-image
        salt-cloud -a vm_disk_save my-vm disk_id=1 image_name=my-new-image image_type=CONTEXT snapshot_id=10

def vm_disk_save(name, kwargs=None, call=None):
    '''
    Sets the disk to be saved in the given image.

    .. versionadded:: 2016.3.0

    name
        The name of the VM containing the disk to save.

    disk_id
        The ID of the disk to save.

    image_name
        The name of the new image where the disk will be saved.

    image_type
        The type for the new image. If not set, then the default ``ONED`` Configuration
        will be used. Other valid types include: OS, CDROM, DATABLOCK, KERNEL, RAMDISK,
        and CONTEXT.

    snapshot_id
        The ID of the snapshot to export. If not set, the current image state will be
        used.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a vm_disk_save my-vm disk_id=1 image_name=my-new-image
        salt-cloud -a vm_disk_save my-vm disk_id=1 image_name=my-new-image image_type=CONTEXT snapshot_id=10
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The vm_disk_save action must be called with -a or --action.'
        )

    if kwargs is None:
        kwargs = {}

    disk_id = kwargs.get('disk_id', None)
    image_name = kwargs.get('image_name', None)
    image_type = kwargs.get('image_type', '')
    snapshot_id = int(kwargs.get('snapshot_id', '-1'))

    if disk_id is None or image_name is None:
        raise SaltCloudSystemExit(
            'The vm_disk_save function requires a \'disk_id\' and an \'image_name\' '
            'to be provided.'
        )

    server, user, password = _get_xml_rpc()
    auth = ':'.join([user, password])
    vm_id = int(get_vm_id(kwargs={'name': name}))
    response = server.one.vm.disksave(auth,
                                      vm_id,
                                      int(disk_id),
                                      image_name,
                                      image_type,
                                      snapshot_id)

    data = {
        'action': 'vm.disksave',
        'saved': response[0],
        'image_id': response[1],
        'error_code': response[2],
    }

    return data