Commit 9585a481 authored by Daniele Venzano's avatar Daniele Venzano

Use address information from the Docker config file

For the Docker back-end the address that should be published for port
mapping should be taken from the config file. Docker by default publishes
on 0.0.0.0.
parent ce5c226f
......@@ -176,16 +176,14 @@ class DockerClient:
if container.attrs['NetworkSettings']['Ports'] is not None:
for port in container.attrs['NetworkSettings']['Ports']:
if container.attrs['NetworkSettings']['Ports'][port] is not None:
mapping = (
container.attrs['NetworkSettings']['Ports'][port][0]['HostIp'],
container.attrs['NetworkSettings']['Ports'][port][0]['HostPort']
)
info['ports'][port] = mapping
info['ports'][port] = container.attrs['NetworkSettings']['Ports'][port][0]['HostPort']
else:
info['ports'][port] = None
info['cpu_period'] = container.attrs['HostConfig']['CpuPeriod']
info['cpu_quota'] = container.attrs['HostConfig']['CpuQuota']
info['memory_hard_limit'] = container.attrs['HostConfig']['Memory']
info['memory_soft_limit'] = container.attrs['HostConfig']['MemoryReservation']
return info
......
......@@ -29,6 +29,7 @@ class DockerHostConfig:
def __init__(self):
self.name = None
self.address = None
self.external_address = None
self.tls = False
self.tls_cert = None
self.tls_key = None
......@@ -50,7 +51,8 @@ class DockerConfig:
host = DockerHostConfig()
host.name = section
try:
host.address = config[section]['address']
host.address = config[section]['docker_address']
host.external_address = config[section]['external_address']
host.tls = config.getboolean(section, 'use_tls')
if host.tls:
host.tls_cert = config[section]['tls_cert']
......
......@@ -90,7 +90,7 @@ class DockerStateSynchronizer(threading.Thread):
for service in service_list:
assert isinstance(service, Service)
if service.backend_id in containers:
self._update_service_status(service, containers[service.backend_id])
self._update_service_status(service, containers[service.backend_id], host_config)
else:
if service.backend_status == service.BACKEND_DESTROY_STATUS:
continue
......@@ -116,13 +116,12 @@ class DockerStateSynchronizer(threading.Thread):
for cont in container_list:
stats[cont['id']] = my_engine.stats(cont['id'], stream=False)
node_stats.memory_reserved = sum([stat['memory_stats']['limit'] for stat in stats.values() if 'limit' in stat['memory_stats'] and stat['memory_stats']['limit'] != node_stats.memory_total])
memory_in_use = sum([stat['memory_stats']['usage'] for stat in stats.values() if 'usage' in stat['memory_stats']])
node_stats.memory_free = node_stats.memory_total - memory_in_use
node_stats.memory_reserved = sum([cont['memory_soft_limit'] for cont in container_list if cont['memory_soft_limit'] != node_stats.memory_total])
node_stats.memory_in_use = sum([stat['memory_stats']['usage'] for stat in stats.values() if 'usage' in stat['memory_stats']])
node_stats.cores_reserved = sum([cont['cpu_quota'] / cont['cpu_period'] for cont in container_list if cont['cpu_period'] != 0])
node_stats.cores_free = node_stats.cores_total - sum([self._get_core_usage(stat) for stat in stats.values()])
node_stats.cores_in_use = sum([self._get_core_usage(stat) for stat in stats.values()])
def _get_core_usage(self, stat):
try:
......@@ -134,7 +133,7 @@ class DockerStateSynchronizer(threading.Thread):
cpu_time_pre = stat['precpu_stats']['cpu_usage']['total_usage']
return (cpu_time_now - cpu_time_pre) / ((this_read_ts - pre_read_ts).total_seconds() * 1000000000)
def _update_service_status(self, service: Service, container):
def _update_service_status(self, service: Service, container, host_config: DockerHostConfig):
"""Update the service status."""
if service.backend_status != container['state']:
old_status = service.backend_status
......@@ -142,7 +141,7 @@ class DockerStateSynchronizer(threading.Thread):
log.debug('Updated service status, {} from {} to {}'.format(service.name, old_status, container['state']))
for port in service.ports:
if port.internal_name in container['ports'] and container['ports'][port.internal_name] is not None:
port.activate(container['ports'][port.internal_name][0], container['ports'][port.internal_name][1])
port.activate(host_config.external_address, container['ports'][port.internal_name])
else:
port.reset()
......
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