Create a directory in etcd.

    name
        The etcd directory name, for example: ``/foo/bar/baz``.
    profile
        Optional, defaults to ``None``. Sets the etcd profile to use which has
        been defined in the Salt Master config.

        .. code-block:: yaml

            my_etd_config:
              etcd.host: 127.0.0.1
              etcd.port: 4001

def directory(name, profile=None, **kwargs):
    '''
    Create a directory in etcd.

    name
        The etcd directory name, for example: ``/foo/bar/baz``.
    profile
        Optional, defaults to ``None``. Sets the etcd profile to use which has
        been defined in the Salt Master config.

        .. code-block:: yaml

            my_etd_config:
              etcd.host: 127.0.0.1
              etcd.port: 4001
    '''

    created = False

    rtn = {
        'name': name,
        'comment': 'Directory exists',
        'result': True,
        'changes': {}
    }

    current = __salt__['etcd.get'](name, profile=profile, recurse=True, **kwargs)
    if not current:
        created = True

    result = __salt__['etcd.set'](name, None, directory=True, profile=profile, **kwargs)

    if result and result != current:
        if created:
            rtn['comment'] = 'New directory created'
            rtn['changes'] = {
                name: 'Created'
            }

    return rtn