Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dockerfiles
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Picasoft
Technique
Dockerfiles
Commits
1b4fbc6e
Unverified
Commit
1b4fbc6e
authored
5 years ago
by
Stephane Bonnet
Browse files
Options
Downloads
Patches
Plain Diff
doc (wip)
parent
db1bae27
No related branches found
Branches containing commit
No related tags found
2 merge requests
!43
WIP: Acme copy certs dev
,
!42
Pica openldap dev
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
acme-copy-certs/app/service_manager.py
+25
-21
25 additions, 21 deletions
acme-copy-certs/app/service_manager.py
with
25 additions
and
21 deletions
acme-copy-certs/app/service_manager.py
+
25
−
21
View file @
1b4fbc6e
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment