Commit fb80641c authored by Daniele Venzano's avatar Daniele Venzano

Expose service status in the web and CLI interfaces

parent 4e2e3ca4
......@@ -31,14 +31,13 @@
{% for s in services_info %}
<li class="container_name" id="{{ s['id'] }}">{{ s['name'] }}</li>
<ul>
<li>Status: {{ s['status'] }}</li>
<li>Zoe status: {{ s['status'] }}</li>
<li>Docker status: {{ s['docker_status'] }}</li>
{% if s['docker_status'] == 'started' %}
{% for p in s['description']['ports'] %}
{% if s['ip_address'] == None %}
<li>Inactive</li>
{% else %}
<li><a href="{{ p['protocol'] }}://{{ s['ip_address'] }}:{{ p['port_number'] }}{{ p['path'] }}">{{ p['name'] }}</a></li>
{% endif %}
{% endfor %}
{% endif %}
</ul>
{% endfor %}
</ul>
......
......@@ -109,8 +109,11 @@ def exec_get_cmd(args):
print('Application name: {}'.format(app['name']))
for c_id in execution['services']:
service = cont_api.get(c_id)
print('Service {} (ID: {})'.format(service['name'], service['id']))
print(' - zoe status: {}'.format(service['status']))
print(' - docker status: {}'.format(service['docker_status']))
if service['docker_status'] == 'started':
ip = service['ip_address']
print('Service {} (ID: {}, {})'.format(service['name'], service['id'], service['status']))
for port in service['description']['ports']:
print(' - {}: {}://{}:{}{}'.format(port['name'], port['protocol'], ip, port['port_number'], port['path']))
......
......@@ -319,10 +319,10 @@ class Service(Base):
STARTING_STATUS = "starting"
DOCKER_UNDEFINED_STATUS = 'undefined'
DOCKER_CREATE_STATUS = 'create'
DOCKER_START_STATUS = 'start'
DOCKER_DIE_STATUS = 'die'
DOCKER_DESTROY_STATUS = 'destroy'
DOCKER_CREATE_STATUS = 'created'
DOCKER_START_STATUS = 'started'
DOCKER_DIE_STATUS = 'dead'
DOCKER_DESTROY_STATUS = 'destroyed'
def __init__(self, d, sql_manager):
super().__init__(d, sql_manager)
......@@ -377,24 +377,13 @@ class Service(Base):
def set_docker_status(self, new_status):
"""Docker has emitted an event related to this service."""
if new_status == 'create':
new_status = self.DOCKER_CREATE_STATUS
elif new_status == 'start':
new_status = self.DOCKER_START_STATUS
elif new_status == 'die':
new_status = self.DOCKER_DIE_STATUS
elif new_status == 'destroy':
new_status = self.DOCKER_DESTROY_STATUS
else:
log.error('Unknown docker status: {}'.format(new_status))
return
self.sql_manager.service_update(self.id, docker_status=new_status)
log.debug("service {}, status updated to {}".format(self.id, new_status))
@property
def ip_address(self):
"""Getter for the service IP address, queries Swarm as the IP address changes outside our control."""
if self.status != self.ACTIVE_STATUS:
if self.docker_status != self.DOCKER_START_STATUS:
return {}
swarm = SwarmClient(get_conf())
s_info = swarm.inspect_container(self.docker_id)
......
......@@ -69,13 +69,13 @@ class ZoeMonitor(threading.Thread):
if 'exec' in event['Action']:
pass
elif 'create' in event['Action']:
service.set_docker_status('create')
service.set_docker_status(service.DOCKER_CREATE_STATUS)
elif 'start' in event['Action']:
service.set_docker_status('start')
service.set_docker_status(service.DOCKER_START_STATUS)
elif 'die' in event['Action']:
service.set_docker_status('die')
service.set_docker_status(service.DOCKER_DIE_STATUS)
elif 'destroy' in event['Action']:
service.set_docker_status('destroy')
service.set_docker_status(service.DOCKER_DESTROY_STATUS)
else:
log.debug('Unmanaged container action: {}'.format(event['Action']))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment