.. versionadded:: 2019.2.0

    Save the configuration to a file on the local file system.

    source: ``running``
        The configuration source. Choose from: ``running``, ``candidate``,
        ``startup``. Default: ``running``.

    path
        Absolute path to file where to save the configuration.
        To push the files to the Master, use
        :mod:`cp.push <salt.modules.cp.push>` Execution function.

    CLI Example:

    .. code-block:: bash

        salt '*' net.save_config source=running

def save_config(source=None,
                path=None):
    '''
    .. versionadded:: 2019.2.0

    Save the configuration to a file on the local file system.

    source: ``running``
        The configuration source. Choose from: ``running``, ``candidate``,
        ``startup``. Default: ``running``.

    path
        Absolute path to file where to save the configuration.
        To push the files to the Master, use
        :mod:`cp.push <salt.modules.cp.push>` Execution function.

    CLI Example:

    .. code-block:: bash

        salt '*' net.save_config source=running
    '''
    if not source:
        source = 'running'
    if not path:
        path = salt.utils.files.mkstemp()
    running_config = __salt__['net.config'](source=source)
    if not running_config or not running_config['result']:
        log.error('Unable to retrieve the config')
        return running_config
    with salt.utils.files.fopen(path, 'w') as fh_:
        fh_.write(running_config['out'][source])
    return {
        'result': True,
        'out': path,
        'comment': '{source} config saved to {path}'.format(source=source, path=path)
    }