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

Added the docker_actions module

parent 4cd2f1ba
No related branches found
No related tags found
2 merge requests!43WIP: Acme copy certs dev,!42Pica openldap dev
import docker
class DockerAction:
def __init__(self, docker_client, container_id):
self.client = docker_client
self.container_id = container_id
pass
def exec(self, id):
c = self.client.container.get(self.container_id)
if c.status == 'running':
self.action(c)
def action(self, container):
pass
class RestartDockerAction(DockerAction):
def __init__(self, docker_client, container_id):
super().__init__(docker_client, container_id)
def action(self, container):
try:
container.restart()
except docker.errors.APIError:
print('Unable to restart container {0}({1})'.format(container.name,
container.id))
class KillDockerAction(DockerAction):
def __init__(self, docker_client, container_id, signal='SIGKILL'):
super().__init__(docker_client, container_id)
self.signal = signal
def action(self, container):
try:
container.kill(self.signal)
except docker.errors.APIError:
print('Unable to kill container {0}({1}) with signal {2}'
.format(container.name, self.container_id, self.signal))
\ 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