<commit_before>
# -*- coding: utf-8 -*-
"""
Docker Swarm Module using Docker's Python SDK
=============================================

:codeauthor: <NAME> <<EMAIL>>

.. versionadded:: Oxygen

The Docker Swarm Module is used to manage and create Docker Swarms.

Dependencies
------------

- Docker installed on the host
- Docker python sdk >= 2.5.1

Docker Python SDK
-----------------
pip install -U docker

More information: https://docker-py.readthedocs.io/en/stable/
"""
# Import python libraries
from __future__ import absolute_import
import salt.utils.json

try:
    import docker
    HAS_DOCKER = True
    def __init__(self):
        __context__['client'] = docker.from_env()
        __context__['server_name'] = __grains__['id']

except ImportError:
    HAS_DOCKER = False

__virtualname__ = 'swarm'


def __virtual__():
    '''
    Load this module if the docker python module is installed
    '''
    if HAS_DOCKER:
        return __virtualname__
    return False, 'The swarm module failed to load: Docker python module is not avaialble.'


def swarm_tokens():
    '''
    Get the Docker Swarm Manager or Worker join tokens

    CLI Example:

    .. code-block:: bash

      salt '*' swarm.swarm_tokens<commit_msg>Use if HAS_DOCKER in __init__<commit_after>
# -*- coding: utf-8 -*-
"""
Docker Swarm Module using Docker's Python SDK
=============================================

:codeauthor: <NAME> <<EMAIL>>

.. versionadded:: Oxygen

The Docker Swarm Module is used to manage and create Docker Swarms.

Dependencies
------------

- Docker installed on the host
- Docker python sdk >= 2.5.1

Docker Python SDK
-----------------
pip install -U docker

More information: https://docker-py.readthedocs.io/en/stable/
"""
# Import python libraries
from __future__ import absolute_import
import salt.utils.json

try:
    import docker
    HAS_DOCKER = True
except ImportError:
    HAS_DOCKER = False

__virtualname__ = 'swarm'


def __virtual__():
    '''
    Load this module if the docker python module is installed
    '''
    if HAS_DOCKER:
        return __virtualname__
    return False, 'The swarm module failed to load: Docker python module is not avaialble.'


def __init__(self):
    if HAS_DOCKER:
        __context__['client'] = docker.from_env()
    __context__['server_name'] = __grains__['id']


def swarm_tokens():
    '''
    Get the Docker Swarm Manager or Worker join tokens

    CLI Example:

    .. code-block:: bash

      salt '*' swarm.swarm_tokens
{'fraction_non_alphanumeric': 0.14891041162227603, 'fraction_numerical': 0.003228410008071025, 'mean_word_length': 3.117940199335548, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5404277', 'n_tokens_mistral': 792, 'n_tokens_neox': 720, 'n_words': 245}