Skip to content
Snippets Groups Projects
Commit 516e10ef authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-379: Added docker client.

parent a44366c3
No related branches found
No related tags found
1 merge request!125L2SS-379: Add a device to monitor/manage the docker containers.
import logging
import docker
from .comms_client import CommClient
logger = logging.getLogger()
class DockerClient(CommClient):
"""
Controls & queries running docker containers.
"""
def start(self):
super().start()
def __init__(self, base_url, fault_func, streams):
super().__init__(fault_func, streams)
self.base_url = base_url
def connect(self):
"""
Function used to connect to the client.
"""
if not self.connected:
self.client = docker.DockerClient(self.base_url)
return super().connect()
def ping(self):
return True
def disconnect(self):
self.client = None
return super().disconnect()
def setup_value_conversion(self, attribute):
"""
gives the client access to the attribute_wrapper object in order to access all data it could potentially need.
the OPC ua read/write functions require the dimensionality and the type to be known
"""
return
def setup_attribute(self, annotation, attribute):
"""
MANDATORY function: is used by the attribute wrapper to get read/write functions. must return the read and write functions
"""
container_name = annotation["container"]
# get all the necessary data to set up the read/write functions from the attribute_wrapper
self.setup_value_conversion(attribute)
def read_function():
try:
container = self.client.containers.get(container_name)
except docker.errors.NotFound:
return False
return container.status == 'running'
def write_function(value):
container = self.client.containers.get(container_name)
if value:
container.start()
else:
container.stop()
return read_function, write_function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment