Attaches a new disk to the given virtual machine.

    .. versionadded:: 2016.3.0

    name
        The name of the VM for which to attach the new disk.

    path
        The path to a file containing a single disk vector attribute.
        Syntax within the file can be the usual attribute=value or XML.
        Can be used instead of ``data``.

    data
        Contains the data needed to attach a single disk vector attribute.
        Syntax can be the usual attribute=value or XML. Can be used instead
        of ``path``.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a vm_attach my-vm path=/path/to/disk_file.txt
        salt-cloud -a vm_attach my-vm data="DISK=[DISK_ID=1]"

def vm_attach(name, kwargs=None, call=None):
    '''
    Attaches a new disk to the given virtual machine.

    .. versionadded:: 2016.3.0

    name
        The name of the VM for which to attach the new disk.

    path
        The path to a file containing a single disk vector attribute.
        Syntax within the file can be the usual attribute=value or XML.
        Can be used instead of ``data``.

    data
        Contains the data needed to attach a single disk vector attribute.
        Syntax can be the usual attribute=value or XML. Can be used instead
        of ``path``.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a vm_attach my-vm path=/path/to/disk_file.txt
        salt-cloud -a vm_attach my-vm data="DISK=[DISK_ID=1]"
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The vm_attach action must be called with -a or --action.'
        )

    if kwargs is None:
        kwargs = {}

    path = kwargs.get('path', None)
    data = kwargs.get('data', None)

    if data:
        if path:
            log.warning(
                'Both the \'data\' and \'path\' arguments were provided. '
                '\'data\' will take precedence.'
            )
    elif path:
        with salt.utils.files.fopen(path, mode='r') as rfh:
            data = rfh.read()
    else:
        raise SaltCloudSystemExit(
            'The vm_attach function requires either \'data\' or a file '
            '\'path\' 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.attach(auth, vm_id, data)

    ret = {
        'action': 'vm.attach',
        'attached': response[0],
        'vm_id': response[1],
        'error_code': response[2],
    }

    return ret