Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
516e10ef
Commit
516e10ef
authored
3 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-379
: Added docker client.
parent
a44366c3
No related branches found
No related tags found
1 merge request
!125
L2SS-379: Add a device to monitor/manage the docker containers.
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
devices/clients/docker_client.py
+71
-0
71 additions, 0 deletions
devices/clients/docker_client.py
with
71 additions
and
0 deletions
devices/clients/docker_client.py
0 → 100644
+
71
−
0
View file @
516e10ef
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
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