Ensure that the named export is present with the given options

    name
        The export path to configure

    clients
        A list of hosts and the options applied to them.
        This option may not be used in combination with
        the 'hosts' or 'options' shortcuts.

    .. code-block:: yaml

        - clients:
          # First export
          - hosts: '10.0.2.0/24'
            options:
              - 'rw'
          # Second export
          - hosts: '*.example.com'
            options:
              - 'ro'
              - 'subtree_check'

    hosts
        A string matching a number of hosts, for example:

    .. code-block:: yaml

        hosts: '10.0.2.123'

        hosts: '10.0.2.0/24'

        hosts: 'minion1.example.com'

        hosts: '*.example.com'

        hosts: '*'

    options
        A list of NFS options, for example:

    .. code-block:: yaml

        options:
          - 'rw'
          - 'subtree_check'

def present(name,
            clients=None,
            hosts=None,
            options=None,
            exports='/etc/exports'):
    '''
    Ensure that the named export is present with the given options

    name
        The export path to configure

    clients
        A list of hosts and the options applied to them.
        This option may not be used in combination with
        the 'hosts' or 'options' shortcuts.

    .. code-block:: yaml

        - clients:
          # First export
          - hosts: '10.0.2.0/24'
            options:
              - 'rw'
          # Second export
          - hosts: '*.example.com'
            options:
              - 'ro'
              - 'subtree_check'

    hosts
        A string matching a number of hosts, for example:

    .. code-block:: yaml

        hosts: '10.0.2.123'

        hosts: '10.0.2.0/24'

        hosts: 'minion1.example.com'

        hosts: '*.example.com'

        hosts: '*'

    options
        A list of NFS options, for example:

    .. code-block:: yaml

        options:
          - 'rw'
          - 'subtree_check'

    '''
    path = name
    ret = {'name': name,
           'changes': {},
           'result': None,
           'comment': ''}

    if not clients:
        if not hosts:
            ret['result'] = False
            ret['comment'] = 'Either \'clients\' or \'hosts\' must be defined'
            return ret
        # options being None is handled by add_export()
        clients = [{'hosts': hosts, 'options': options}]

    old = __salt__['nfs3.list_exports'](exports)
    if path in old:
        if old[path] == clients:
            ret['result'] = True
            ret['comment'] = 'Export {0} already configured'.format(path)
            return ret

        ret['changes']['new'] = clients
        ret['changes']['old'] = old[path]
        if __opts__['test']:
            ret['result'] = None
            ret['comment'] = 'Export {0} would be changed'.format(path)
            return ret

        __salt__['nfs3.del_export'](exports, path)

    else:
        ret['changes']['old'] = None
        ret['changes']['new'] = clients
        if __opts__['test']:
            ret['result'] = None
            ret['comment'] = 'Export {0} would be added'.format(path)
            return ret

    add_export = __salt__['nfs3.add_export']
    for exp in clients:
        add_export(exports, path, exp['hosts'], exp['options'])

    ret['changes']['new'] = clients

    try_reload = __salt__['nfs3.reload_exports']()
    ret['comment'] = try_reload['stderr']
    ret['result'] = try_reload['result']
    return ret