...
 
Commits (9)
...@@ -3,6 +3,10 @@ __pycache__/ ...@@ -3,6 +3,10 @@ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
# Mkdocs output
/site/
# C extensions # C extensions
*.so *.so
......
...@@ -9,6 +9,7 @@ A set of python scripts displaying the local docker containers structure and sta ...@@ -9,6 +9,7 @@ A set of python scripts displaying the local docker containers structure and sta
* python 3.5 * python 3.5
* docker-py * docker-py
* termcolor
## Install ## Install
...@@ -17,20 +18,32 @@ You can install this tool from PyPI: ...@@ -17,20 +18,32 @@ You can install this tool from PyPI:
``` ```
alcibiade@mobydick:~$ sudo pip3 install docker-ascii-map alcibiade@mobydick:~$ sudo pip3 install docker-ascii-map
Collecting docker-ascii-map Collecting docker-ascii-map
Downloading docker-ascii-map-0.3.tar.gz Downloading docker-ascii-map-0.4.1.tar.gz
Installing collected packages: docker-ascii-map Installing collected packages: docker-ascii-map
Running setup.py install for docker-ascii-map ... done Running setup.py install for docker-ascii-map ... done
Successfully installed docker-ascii-map-0.3 Successfully installed docker-ascii-map-0.4.1
``` ```
## Usage ## Usage
```
usage: docker-ascii-map [-h] [-v] [-c] [-m]
Display the docker host contents on a visual map.
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-c, --color Use color in map display
-m, --mono Render the map in monochrome
```
Below is a sample of a host running several applications on multiple networks. Below is a sample of a host running several applications on multiple networks.
A container is routing traffic to these networks from the host. A container is routing traffic to these networks from the host.
``` ```
alcibiade@mobydick:~/docker-ascii-map$ docker-ascii-map.py alcibiade@mobydick:~/docker-ascii-map$ docker-ascii-map
+- chesscorp_default ----------------+ +- chesscorp_default ----------------+
| [✓] chesscorp_web_1 | | [✓] chesscorp_web_1 |
......
__version__ = '0.4.1' __version__ = '0.4.2'
import argparse
import os
from typing import Tuple
from docker_ascii_map import __version__
def get_input_parameters() -> Tuple[bool]:
parser = argparse.ArgumentParser(description='Display the docker host contents on a visual map.')
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('-c', '--color', action='store_const', const='color', help='Use color in map display')
parser.add_argument('-m', '--mono', action='store_const', const='mono', help='Render the map in monochrome')
terminal = os.getenv('TERM')
args = parser.parse_args()
color_mode = False
if terminal:
color_mode = 'color' in terminal
if args.color:
color_mode = True
if args.mono:
color_mode = False
return color_mode, None
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse
import sys import sys
from docker_ascii_map import __version__
from docker_ascii_map.docker_config import ConfigParser
from docker_ascii_map.argument_parser import get_input_parameters
from docker_ascii_map.ascii_render import Renderer from docker_ascii_map.ascii_render import Renderer
from docker_ascii_map.docker_config import ConfigParser
parser = argparse.ArgumentParser(description='Display the docker host contents on a visual map.')
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('-c', '--color', action='store_const', const='color', help='Use color in map display')
parser.add_argument('-m', '--mono', action='store_const', const='mono', help='Render the map in monochrome')
if __name__ == '__main__': if __name__ == '__main__':
args = parser.parse_args() color_mode = get_input_parameters()[0]
color_mode = args.color and not args.mono
config_parser = ConfigParser() config_parser = ConfigParser()
renderer = Renderer() renderer = Renderer()
......
from typing import List import docker
from docker import Client from typing import List
class PortMapping: class PortMapping:
...@@ -34,7 +34,7 @@ class Configuration: ...@@ -34,7 +34,7 @@ class Configuration:
class ConfigParser: class ConfigParser:
def __init__(self): def __init__(self):
self._client = Client() self._client = docker.from_env(assert_hostname=False)
def get_configuration(self) -> Configuration: def get_configuration(self) -> Configuration:
containers = [] containers = []
......
# docker-ascii-map
A set of python scripts displaying the local docker containers structure and status on an ascii map.
site_name: docler-ascii-mao Documentation
site_description: A set of python scripts displaying the local docker containers structure and status on an ascii map.
repo_url: https://github.com/ChessCorp/docker-ascii-map
theme: readthedocs
pages:
- Home: index.md
...@@ -7,14 +7,23 @@ setup( ...@@ -7,14 +7,23 @@ setup(
version=__version__, version=__version__,
packages=['docker_ascii_map'], packages=['docker_ascii_map'],
package_dir={'docker_ascii_map': 'docker_ascii_map'}, package_dir={'docker_ascii_map': 'docker_ascii_map'},
scripts=['docker_ascii_map/docker-ascii-map.py'], scripts=['docker_ascii_map/docker-ascii-map'],
test_suite='tests', test_suite='tests',
setup_requires=['pytest-runner'], setup_requires=['pytest-runner'],
install_requires=['docker-py', 'termcolor'], install_requires=['docker-py >= 1.10.0', 'termcolor >= 1.1.0'],
tests_require=['pytest'], tests_require=['pytest'],
url='https://github.com/ChessCorp/docker-ascii-map', url='https://github.com/ChessCorp/docker-ascii-map',
license='MIT', license='MIT',
author='Yannick Kirschhoffer', author='Yannick Kirschhoffer',
author_email='alcibiade@alcibiade.org', author_email='alcibiade@alcibiade.org',
description='A set of python scripts displaying the local docker containers structure and status on an ascii map.' description='A set of python scripts displaying the local docker containers structure and status on an ascii map.',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Topic :: System :: Systems Administration',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
],
) )
import unittest
from argparse import ArgumentParser
from unittest.mock import patch
import docker_ascii_map.argument_parser
class Args:
def __init__(self, mono=None, color=None):
self.mono = mono
self.color = color
class ParametersTests(unittest.TestCase):
def test_monoterm(self):
with patch('os.getenv', return_value='vt100') as mock_getenv:
with patch.object(ArgumentParser, 'parse_args', return_value=Args()) as mock_parse:
r = docker_ascii_map.argument_parser.get_input_parameters()
self.assertEqual(False, r[0])
def test_colorterm(self):
with patch('os.getenv', return_value='xterm-256color') as mock_getenv:
with patch.object(ArgumentParser, 'parse_args', return_value=Args()) as mock_parse:
r = docker_ascii_map.argument_parser.get_input_parameters()
self.assertEqual(True, r[0])
if __name__ == '__main__':
unittest.main()