Add ID in container

pull/1/head
Christophe Mehay 8 years ago
parent 7518e360be
commit 99578fd6ec

@ -181,12 +181,21 @@ You have 4 available objects in your templates.
- container environment
- `names`
- List of containers names
- Names are sorted by length, but container ID will be the last element.
- `id`
- Hexadecimal container ID
- `links`
- Tuple of `link` object related to this container
#### environ
`environ` is the environment of the container (os.environ).
## Setup
Some setups can be overridden using environment variables.
`ENTRYPOINT-CONFIG` overrides `entrypoint-config.yml` file.
### Running Tests
To run tests, ensure that `docker-compose` and `make` are installed and run

@ -51,7 +51,7 @@ class Config(object):
self._args = args
@property
def as_config(self):
def has_config(self):
"Has config file provided."
return len(self._config) is not 0

@ -9,10 +9,11 @@ class Container(object):
"""Container handles a single container link"""
def __init__(self, ip, env, names, links=None):
def __init__(self, ip, env, names, id, links=None):
self.ip = ip
self.environ = env
self.names = names
self.id = id
self._set_links(links)
def _set_links(self, links):

@ -73,7 +73,8 @@ class DockerLinks(object):
names.sort(key=len)
hexa.sort()
item["names"] = names + hexa
item["names"] = names
item["id"] = hexa
def links(self, *args):
"Return dictionnary of links in container"
@ -102,6 +103,7 @@ class DockerLinks(object):
ctn.append(Container(ip=ip,
env=item['environment'],
names=item['names'],
id=item['id'][0],
links=links))
self._containers = tuple(ctn)
return self._containers

@ -34,6 +34,8 @@ class Entrypoint(object):
def __init__(self, conf=ENTRYPOINT_FILE, args=[]):
self._set_logguer()
if 'ENTRYPOINT_CONFIG' in os.environ:
conf = os.environ['ENTRYPOINT_CONFIG']
try:
self.config = Config(conf=conf, args=args)
except Exception as err:

@ -9,7 +9,7 @@ setup(
name='pyentrypoint',
version='0.1.16',
version='0.1.17',
packages=find_packages(),

@ -98,7 +98,7 @@ def test_containers():
assert len(ctn.links) == 0
# Test sorted names
int(ctn.names[-1], base=16)
int(ctn.id, base=16)
assert len(ctn.names[0]) <= len(ctn.names[1])
@ -133,6 +133,10 @@ def test_templates():
for test_name in test_names:
assert test_name in test['All names']
# test id
for id in test['ID']:
int(id, base=16)
def test_conf_commands():
entry = Entrypoint(conf='configs/base.yml')
@ -180,3 +184,12 @@ def test_command():
assert f.readline().startswith('OK')
assert os.stat(test).st_uid == uid
assert os.stat(test).st_gid == gid
def test_config_file():
os.environ['ENTRYPOINT_CONFIG'] = 'configs/base.yml'
entry = Entrypoint()
assert entry.config.has_config
del os.environ['ENTRYPOINT_CONFIG']

@ -37,3 +37,8 @@ All names:
- {{name}}
{% endfor %}
{% endfor %}
ID:
{% for container in containers %}
- {{container.id}}
{% endfor %}

Loading…
Cancel
Save