Skip to content
Snippets Groups Projects
Unverified Commit 1b4fbc6e authored by Stephane Bonnet's avatar Stephane Bonnet
Browse files

doc (wip)

parent db1bae27
No related branches found
No related tags found
2 merge requests!43WIP: Acme copy certs dev,!42Pica openldap dev
......@@ -5,13 +5,15 @@ services whose certificates are to be updated by the ssytem.
Classes
-------
Service:
Service
A class representing a single service
ServiceManager:
ServiceManager
A class handling a collection of services
"""
from threading import Lock
class Service:
"""
A service wrapper This object represents a docker service
......@@ -97,39 +99,41 @@ class ServicesManager:
self.services_by_id = {}
self.services_by_host = {}
self.updater = updater
self.lock = Lock()
def add(self, service):
""" Adds a service to the collection and enables handling of its
certificates
"""
self.services_by_id[service.id] = service
if service.host not in self.services_by_host:
self.services_by_host[service.host] = [service]
else:
self.services_by_host[service.host].append(service)
with self.lock:
self.services_by_id[service.id] = service
if service.host not in self.services_by_host:
self.services_by_host[service.host] = [service]
else:
self.services_by_host[service.host].append(service)
self.updater.add(service.host)
self.updater.add(service.host)
self.update()
def remove(self, id):
""" Removes a service by its id from the collection and disables handling
of its certificates
"""
if id in self.services_by_id:
service = self.services_by_id[id]
host = service.host
self.services_by_host[host].remove(service)
del self.services_by_id[id]
if len(self.services_by_host[host]) == 0:
del self.services_by_host[host]
self.updater.remove(host)
with self.lock:
if id in self.services_by_id:
service = self.services_by_id[id]
host = service.host
self.services_by_host[host].remove(service)
del self.services_by_id[id]
if len(self.services_by_host[host]) == 0:
del self.services_by_host[host]
self.updater.remove(host)
def update(self):
""" Updates the certificates of the services if needed. If a certificate
has changed, exectute the associated docker action on the service container.
"""
changed_hosts = self.updater.update()
for h in changed_hosts:
for s in self.services_by_host[h]:
s.run_action()
\ No newline at end of file
with self.lock:
for h in self.updater.update():
for s in self.services_by_host[h]:
s.run_action()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment