-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.py
64 lines (52 loc) · 2.03 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import logging
class Config(object):
def __init__(self, configuration_from_fixture):
self._configuration_from_fixture = configuration_from_fixture
def images(self):
images = []
for configuration in self._configuration_from_fixture:
try:
images.append(configuration['image'])
except KeyError:
logging.error('missing: image')
return sorted(images)
def containers(self):
return self._configuration_from_fixture
def networks(self):
networks = []
for configuration in self._configuration_from_fixture:
try:
if configuration['network'] not in networks:
networks.append(configuration['network'])
except KeyError:
pass
return sorted(networks)
def volumes(self):
volumes = []
for configuration in self._configuration_from_fixture:
try:
for image_volume in configuration['volumes']:
if image_volume not in volumes:
volumes.append(image_volume)
except KeyError:
pass
return sorted(volumes)
@classmethod
def container_kwargs(cls, container):
container_dict = {}
Config._container_kwarg(container_dict, container, 'name')
Config._container_kwarg(container_dict, container, 'ports')
Config._container_kwarg(container_dict, container, 'network')
Config._container_kwarg(container_dict, container, 'volumes')
Config._container_kwarg(container_dict, container, 'command')
Config._container_kwarg(container_dict, container, 'environment')
return container_dict
@classmethod
def _container_kwarg(cls, container_dict, container, key):
try:
container_dict[key] = container[key]
except KeyError:
logging.warning('%s - missing: %s' % (container['image'], key))
return container_dict
class ConfigException(Exception):
pass