holado 0.6.3__py3-none-any.whl → 0.6.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of holado might be problematic. Click here for more details.
- holado/__init__.py +2 -2
- {holado-0.6.3.dist-info → holado-0.6.5.dist-info}/METADATA +42 -1
- {holado-0.6.3.dist-info → holado-0.6.5.dist-info}/RECORD +64 -19
- holado_ais/ais/ais_messages.py +3 -1
- holado_docker/tools/docker_controller/server/grpc/docker_controller_client.py → holado_crypto/__init__.py +15 -20
- holado_crypto/crypto/transport/__init__.py +0 -0
- holado_crypto/crypto/transport/crc.py +40 -0
- holado_docker/tools/docker_controller/server/grpc/docker_controller_server.py → holado_crypto/test/behave/steps/__init__.py +2 -17
- holado_docker/tools/docker_controller/client/rest/docker_controller_client.py +10 -4
- holado_docker/tools/docker_controller/docker_controller_manager.py +5 -3
- holado_docker/tools/docker_controller/server/Dockerfile +9 -7
- holado_docker/tools/docker_controller/server/requirements.txt +1 -2
- holado_docker/tools/docker_controller/server/rest/README +2 -0
- holado_docker/tools/docker_controller/server/rest/api/__init__.py +16 -17
- holado_docker/tools/docker_controller/server/rest/openapi.yaml +20 -3
- holado_docker/tools/docker_controller/server/run_docker_controller_in_docker.sh +6 -6
- holado_docker/tools/docker_viewer/client/rest/docker_viewer_client.py +40 -0
- holado_docker/tools/docker_viewer/docker_viewer_manager.py +44 -0
- holado_docker/tools/docker_viewer/server/Dockerfile +70 -0
- holado_docker/tools/docker_viewer/server/requirements.txt +2 -0
- holado_docker/tools/docker_viewer/server/rest/README +2 -0
- holado_docker/tools/docker_viewer/server/rest/api/__init__.py +40 -0
- holado_docker/tools/docker_viewer/server/rest/initialize_holado.py +72 -0
- holado_docker/tools/docker_viewer/server/rest/openapi.yaml +58 -0
- holado_docker/tools/docker_viewer/server/rest/run.py +28 -0
- holado_docker/tools/docker_viewer/server/run_docker_viewer_in_docker.sh +101 -0
- holado_examples/projects/server_rest/server_rest_example/initialize_holado.py +72 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/db.sqlite3 +0 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/manage.py +22 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/__init__.py +0 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/__init__.py +0 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/admin.py +3 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/apps.py +7 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/migrations/__init__.py +0 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/models.py +3 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/serializers.py +15 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/tests.py +3 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/views.py +24 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/asgi.py +16 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/settings.py +130 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/urls.py +31 -0
- holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/wsgi.py +16 -0
- holado_examples/projects/server_rest/server_rest_example/rest_server.py +37 -0
- holado_examples/scripts/script_custom_initialization.py +16 -0
- holado_examples/scripts/script_minimal_initialization.py +23 -0
- holado_examples/tests/behave/testing_solution/__main__.py +13 -0
- holado_examples/tests/behave/testing_solution/behave_environment.py +35 -0
- holado_examples/tests/behave/testing_solution/environment.py +36 -0
- holado_examples/tests/behave/testing_solution/features/Configuration/Actions/configure_system.feature +10 -0
- holado_examples/tests/behave/testing_solution/features/NonReg/example.feature +26 -0
- holado_examples/tests/behave/testing_solution/initialize_holado.py +62 -0
- holado_examples/tests/behave/testing_solution/logging.conf +102 -0
- holado_examples/tests/behave/testing_solution/requirements.txt +5 -0
- holado_examples/tests/behave/testing_solution/run_test.sh +7 -0
- holado_examples/tests/behave/testing_solution/run_test_nonreg.sh +6 -0
- holado_examples/tests/behave/testing_solution/src/common/tools/path_manager.py +40 -0
- holado_examples/tests/behave/testing_solution/src/config/config_manager.py +30 -0
- holado_examples/tests/behave/testing_solution/src/context/session_context.py +45 -0
- holado_examples/tests/behave/testing_solution/steps/config_steps.py +21 -0
- holado_examples/tests/behave/testing_solution/steps/public_steps.py +10 -0
- holado_python/standard_library/hashlib.py +28 -0
- holado_rest/api/rest/rest_client.py +13 -5
- holado_docker/tools/docker_controller/server/grpc/proto/generated/docker_controler_pb2.py +0 -52
- holado_docker/tools/docker_controller/server/grpc/proto/generated/docker_controler_pb2_grpc.py +0 -233
- {holado-0.6.3.dist-info → holado-0.6.5.dist-info}/WHEEL +0 -0
- {holado-0.6.3.dist-info → holado-0.6.5.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
#################################################
|
|
3
|
+
# HolAdo (Holistic Automation do)
|
|
4
|
+
#
|
|
5
|
+
# (C) Copyright 2021-2025 by Eric Klumpp
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
#
|
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
# The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
|
|
12
|
+
#################################################
|
|
13
|
+
|
|
14
|
+
import logging
|
|
15
|
+
from holado_rest.api.rest.rest_client import RestClient
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class DockerViewerClient(RestClient):
|
|
21
|
+
|
|
22
|
+
def __init__(self, name, url, headers=None):
|
|
23
|
+
super().__init__(name, url, headers)
|
|
24
|
+
|
|
25
|
+
def get_containers_status(self, all_=False):
|
|
26
|
+
if all_:
|
|
27
|
+
response = self.get("container?all=true")
|
|
28
|
+
else:
|
|
29
|
+
response = self.get("container")
|
|
30
|
+
return self.response_result(response, status_ok=[200,204])
|
|
31
|
+
|
|
32
|
+
def get_container_info(self, name, all_=False):
|
|
33
|
+
if all_:
|
|
34
|
+
response = self.get(f"container/{name}?all=true")
|
|
35
|
+
else:
|
|
36
|
+
response = self.get(f"container/{name}")
|
|
37
|
+
return self.response_result(response, status_ok=[200,204])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
#################################################
|
|
3
|
+
# HolAdo (Holistic Automation do)
|
|
4
|
+
#
|
|
5
|
+
# (C) Copyright 2021-2025 by Eric Klumpp
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
#
|
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
# The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
|
|
12
|
+
#################################################
|
|
13
|
+
|
|
14
|
+
import logging
|
|
15
|
+
from holado_core.common.tools.converters.converter import Converter
|
|
16
|
+
import os
|
|
17
|
+
from holado_rest.api.rest.rest_manager import RestManager
|
|
18
|
+
from holado_docker.tools.docker_viewer.client.rest.docker_viewer_client import DockerViewerClient
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class DockerViewerManager(object):
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def new_client(cls, **kwargs):
|
|
27
|
+
if 'name' not in kwargs:
|
|
28
|
+
kwargs['name'] = None
|
|
29
|
+
if 'url' not in kwargs:
|
|
30
|
+
env_use = os.getenv("HOLADO_USE_LOCALHOST", False)
|
|
31
|
+
use_localhost = Converter.is_boolean(env_use) and Converter.to_boolean(env_use)
|
|
32
|
+
|
|
33
|
+
host = "localhost" if use_localhost else os.getenv("HOLADO_DOCKER_VIEWER_NAME", "holado_docker_viewer")
|
|
34
|
+
port = os.getenv("HOLADO_DOCKER_VIEWER_PORT", 8000)
|
|
35
|
+
kwargs['url'] = f"http://{host}:{port}"
|
|
36
|
+
|
|
37
|
+
manager = RestManager(default_client_class=DockerViewerClient)
|
|
38
|
+
res = manager.new_client(**kwargs)
|
|
39
|
+
|
|
40
|
+
return res
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
### Build
|
|
2
|
+
|
|
3
|
+
#FROM python:3.12.9-alpine3.21 AS build
|
|
4
|
+
FROM python:3.12.11-alpine3.22 AS build
|
|
5
|
+
|
|
6
|
+
# Install to build python requirements
|
|
7
|
+
RUN apk update \
|
|
8
|
+
&& apk --no-cache --update add build-base \
|
|
9
|
+
&& apk --update add alpine-sdk \
|
|
10
|
+
&& apk add libffi-dev \
|
|
11
|
+
&& apk add postgresql-dev gcc python3-dev musl-dev \
|
|
12
|
+
&& apk add protobuf-dev
|
|
13
|
+
|
|
14
|
+
# Add tools
|
|
15
|
+
RUN apk --no-cache add bash \
|
|
16
|
+
&& apk --no-cache add nano \
|
|
17
|
+
&& apk --no-cache add curl
|
|
18
|
+
|
|
19
|
+
# Create user
|
|
20
|
+
RUN addgroup appuser \
|
|
21
|
+
&& adduser -G appuser -s /bin/bash -D appuser
|
|
22
|
+
|
|
23
|
+
# Create /code folder
|
|
24
|
+
RUN mkdir /code \
|
|
25
|
+
&& chown -R appuser:appuser /code
|
|
26
|
+
|
|
27
|
+
# Switch to user appuser
|
|
28
|
+
USER appuser
|
|
29
|
+
|
|
30
|
+
# Create python venv and install requirements
|
|
31
|
+
COPY --chown=appuser ./requirements.txt /code/docker_viewer/requirements.txt
|
|
32
|
+
WORKDIR /code/docker_viewer
|
|
33
|
+
RUN python -m venv /code/env \
|
|
34
|
+
&& source /code/env/bin/activate \
|
|
35
|
+
&& pip install -r requirements.txt
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Runtime
|
|
40
|
+
|
|
41
|
+
#FROM python:3.12.9-alpine3.21 AS runtime
|
|
42
|
+
FROM python:3.12.11-alpine3.22 AS runtime
|
|
43
|
+
|
|
44
|
+
# Install for python requirements
|
|
45
|
+
#RUN apk update \
|
|
46
|
+
# && apk --no-cache add libstdc++ \
|
|
47
|
+
# && apk --no-cache add postgresql-dev gcc python3-dev musl-dev
|
|
48
|
+
|
|
49
|
+
# Add tools
|
|
50
|
+
RUN apk --no-cache add bash \
|
|
51
|
+
&& apk --no-cache add nano \
|
|
52
|
+
&& apk --no-cache add curl
|
|
53
|
+
|
|
54
|
+
# Create and switch to user appuser as in build
|
|
55
|
+
RUN addgroup appuser \
|
|
56
|
+
&& adduser -G appuser -s /bin/bash -D appuser
|
|
57
|
+
USER appuser
|
|
58
|
+
|
|
59
|
+
# Copy /code from build
|
|
60
|
+
COPY --chown=appuser --from=build /code /code
|
|
61
|
+
|
|
62
|
+
# Copy docker viewer sources
|
|
63
|
+
COPY --chown=appuser ./rest /code/docker_viewer
|
|
64
|
+
|
|
65
|
+
# Activate permanently python venv
|
|
66
|
+
ENV PATH=/code/env/bin:$PATH
|
|
67
|
+
|
|
68
|
+
WORKDIR /code/docker_viewer
|
|
69
|
+
CMD ["sh", "-c", "uvicorn run:app --host 0.0.0.0 --port $HOLADO_DOCKER_VIEWER_PORT"]
|
|
70
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#################################################
|
|
2
|
+
# HolAdo (Holistic Automation do)
|
|
3
|
+
#
|
|
4
|
+
# (C) Copyright 2021-2025 by Eric Klumpp
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
#
|
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
# The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
|
|
11
|
+
#################################################
|
|
12
|
+
|
|
13
|
+
from flask.views import MethodView
|
|
14
|
+
from holado.common.context.session_context import SessionContext
|
|
15
|
+
import logging
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _get_session_context():
|
|
22
|
+
return SessionContext.instance()
|
|
23
|
+
|
|
24
|
+
class ContainerView(MethodView):
|
|
25
|
+
|
|
26
|
+
def get(self, name=None, all_=False, limit=100):
|
|
27
|
+
_get_session_context().docker_client.update_containers(all_=all_)
|
|
28
|
+
if name is not None:
|
|
29
|
+
if not _get_session_context().docker_client.has_container(name, in_list=False, all_=all_, reset_if_removed=False):
|
|
30
|
+
if all_:
|
|
31
|
+
return f"Container '{name}' doesn't exist", 406
|
|
32
|
+
else:
|
|
33
|
+
return f"Container '{name}' is not running (try with '?all=true' to get information on existing but not running containers)", 406
|
|
34
|
+
|
|
35
|
+
cont = _get_session_context().docker_client.get_container(name, all_=all_)
|
|
36
|
+
res = cont.information
|
|
37
|
+
else:
|
|
38
|
+
names = _get_session_context().docker_client.get_container_names(in_list=False, all_=all_)
|
|
39
|
+
res = [{'name':n, 'status':_get_session_context().docker_client.get_container(n, all_=all_).status} for n in names]
|
|
40
|
+
return res
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
#################################################
|
|
3
|
+
# HolAdo (Holistic Automation do)
|
|
4
|
+
#
|
|
5
|
+
# (C) Copyright 2021-2025 by Eric Klumpp
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
#
|
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
# The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
|
|
12
|
+
#################################################
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
#################################################
|
|
16
|
+
# GOAL: Tools when using a clone of HolAdo project.
|
|
17
|
+
#
|
|
18
|
+
# This file contains methods usefull to initialize environments using a clone of HolAdo project.
|
|
19
|
+
#
|
|
20
|
+
# USAGE:
|
|
21
|
+
# - Copy this file in projects using HolAdo.
|
|
22
|
+
# - Define environment variable HOLADO_PATH with path to cloned HolAdo project.
|
|
23
|
+
# If HOLADO_PATH is defined, sources of cloned HolAdo project are used, else installed holado package is used.
|
|
24
|
+
#################################################
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
import os
|
|
29
|
+
import sys
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def insert_sys_path(path, index=0):
|
|
33
|
+
"""Insert a path in sys.path if it doesn't already exists.
|
|
34
|
+
"""
|
|
35
|
+
if path not in sys.path:
|
|
36
|
+
sys.path.insert(index, path)
|
|
37
|
+
|
|
38
|
+
def insert_sys_paths(list_paths, index=0):
|
|
39
|
+
"""Insert a list of path in sys.path if it doesn't already exists.
|
|
40
|
+
"""
|
|
41
|
+
if list_paths:
|
|
42
|
+
for path in list_paths:
|
|
43
|
+
insert_sys_path(path, index=index)
|
|
44
|
+
|
|
45
|
+
def insert_holado_source_paths(with_test_behave=True):
|
|
46
|
+
"""Insert in sys.path all HolAdo source paths.
|
|
47
|
+
If environment variable HOLADO_PATH is defined with path to HolAdo project, following paths are inserted in sys.path:
|
|
48
|
+
- HOLADO_PATH/src: path to holado modules sources
|
|
49
|
+
- HOLADO_PATH/tests/behave (if with_test_behave==True): path to holado test sources, needed by testing solutions
|
|
50
|
+
"""
|
|
51
|
+
holado_path = os.getenv('HOLADO_PATH')
|
|
52
|
+
if holado_path is None:
|
|
53
|
+
try:
|
|
54
|
+
import holado # @UnusedImport
|
|
55
|
+
except Exception as exc:
|
|
56
|
+
if "No module named" in str(exc):
|
|
57
|
+
raise Exception(f"If environment variable HOLADO_PATH is not defined with path to HolAdo project, 'holado' python package must be installed")
|
|
58
|
+
else:
|
|
59
|
+
raise exc
|
|
60
|
+
else:
|
|
61
|
+
# holado is installed, and all sources are already accessible
|
|
62
|
+
pass
|
|
63
|
+
else:
|
|
64
|
+
print(f"Using HolAdo project installed in '{holado_path}'")
|
|
65
|
+
# import traceback
|
|
66
|
+
# print("".join(traceback.format_list(traceback.extract_stack())))
|
|
67
|
+
# insert_sys_path(holado_path)
|
|
68
|
+
insert_sys_path(os.path.join(holado_path, "src"))
|
|
69
|
+
if with_test_behave:
|
|
70
|
+
insert_sys_path(os.path.join(holado_path, "tests", "behave"))
|
|
71
|
+
|
|
72
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
openapi: "3.0.0"
|
|
2
|
+
info:
|
|
3
|
+
version: "1"
|
|
4
|
+
title: "Docker Viewer API"
|
|
5
|
+
description: |
|
|
6
|
+
API to process some docker actions from anywhere on the network.
|
|
7
|
+
In a microservice architecture, the docker viewer can be run in a docker with special privileges,
|
|
8
|
+
whereas all other microservices have user privileges.
|
|
9
|
+
For example, it is usefull to monitor containers statuses from any terminal on the network.
|
|
10
|
+
paths:
|
|
11
|
+
/container:
|
|
12
|
+
get:
|
|
13
|
+
description: "List containers and their status"
|
|
14
|
+
parameters:
|
|
15
|
+
- in: "query"
|
|
16
|
+
name: "all"
|
|
17
|
+
description: "if set to 'true', list all containers, not only running ones"
|
|
18
|
+
schema:
|
|
19
|
+
type: "boolean"
|
|
20
|
+
default: false
|
|
21
|
+
responses:
|
|
22
|
+
200:
|
|
23
|
+
description: "List of container names with their status"
|
|
24
|
+
content:
|
|
25
|
+
application/json:
|
|
26
|
+
schema:
|
|
27
|
+
type: "array"
|
|
28
|
+
items:
|
|
29
|
+
type: "string"
|
|
30
|
+
/container/{name}:
|
|
31
|
+
get:
|
|
32
|
+
description: "Display all information of a container"
|
|
33
|
+
parameters:
|
|
34
|
+
- in: "path"
|
|
35
|
+
name: "name"
|
|
36
|
+
description: "Container name"
|
|
37
|
+
required: true
|
|
38
|
+
schema:
|
|
39
|
+
type: "string"
|
|
40
|
+
- in: "query"
|
|
41
|
+
name: "all"
|
|
42
|
+
description: "if set to 'true', search container in all containers, not only running ones"
|
|
43
|
+
schema:
|
|
44
|
+
type: "boolean"
|
|
45
|
+
default: false
|
|
46
|
+
responses:
|
|
47
|
+
200:
|
|
48
|
+
description: "Container information"
|
|
49
|
+
content:
|
|
50
|
+
application/json:
|
|
51
|
+
schema:
|
|
52
|
+
type: "string"
|
|
53
|
+
components:
|
|
54
|
+
securitySchemes: {}
|
|
55
|
+
schemas:
|
|
56
|
+
DockerControler:
|
|
57
|
+
properties: {}
|
|
58
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#################################################
|
|
2
|
+
# HolAdo (Holistic Automation do)
|
|
3
|
+
#
|
|
4
|
+
# (C) Copyright 2021-2025 by Eric Klumpp
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
#
|
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
# The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
|
|
11
|
+
#################################################
|
|
12
|
+
|
|
13
|
+
import connexion
|
|
14
|
+
from connexion.resolver import MethodViewResolver
|
|
15
|
+
|
|
16
|
+
# For debug with HolAdo sources, insert HolAdo source paths
|
|
17
|
+
from initialize_holado import insert_holado_source_paths # @UnresolvedImport
|
|
18
|
+
insert_holado_source_paths(with_test_behave=False)
|
|
19
|
+
|
|
20
|
+
# Initialize HolAdo
|
|
21
|
+
from holado import initialize_minimal
|
|
22
|
+
initialize_minimal()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
app = connexion.FlaskApp(__name__, pythonic_params=True)
|
|
26
|
+
app.add_api('openapi.yaml',
|
|
27
|
+
resolver=MethodViewResolver('api'), resolver_error=501,
|
|
28
|
+
pythonic_params=True)
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Script to launch Docker Viewer as a docker image.
|
|
4
|
+
#
|
|
5
|
+
# Docker Viewer exposes a REST API for some docker commands.
|
|
6
|
+
# It is accessible on localhost, and also on a docker network if HOLADO_NETWORK is defined.
|
|
7
|
+
# On all networks, API is accessible on same port (HOLADO_DOCKER_VIEWER_PORT or 8000).
|
|
8
|
+
#
|
|
9
|
+
# REST API specification is in file rest/openapi.yaml.
|
|
10
|
+
#
|
|
11
|
+
# REQUIREMENTS:
|
|
12
|
+
# Have access to any HolAdo registry.
|
|
13
|
+
#
|
|
14
|
+
# Optionally, define in .profile the following variables
|
|
15
|
+
# - HOLADO_DOCKER_VIEWER_PORT: REST API port to use (default: 8000)
|
|
16
|
+
# - HOLADO_IMAGE_REGISTRY: docker image registry to use (default: holado/docker_viewer)
|
|
17
|
+
# - HOLADO_IMAGE_TAG: docker image tag to use (default: latest)
|
|
18
|
+
# - HOLADO_OUTPUT_BASEDIR: absolute path to base output directory (default: [HOME]/.holado/output)
|
|
19
|
+
# - HOLADO_USE_LOCALHOST: force the container network to 'host'.
|
|
20
|
+
# - HOLADO_NETWORK: specify on which network the docker is run.
|
|
21
|
+
#
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
WORK_DIR="$(pwd)"
|
|
25
|
+
|
|
26
|
+
if [[ -z "$HOLADO_IMAGE_REGISTRY" ]]; then
|
|
27
|
+
HOLADO_IMAGE_REGISTRY=holado/docker_viewer
|
|
28
|
+
fi
|
|
29
|
+
if [[ -z "$HOLADO_IMAGE_TAG" ]]; then
|
|
30
|
+
HOLADO_IMAGE_TAG=latest
|
|
31
|
+
fi
|
|
32
|
+
VIEWER_IMAGE=${HOLADO_IMAGE_REGISTRY}:${HOLADO_IMAGE_TAG}
|
|
33
|
+
|
|
34
|
+
# Update docker image
|
|
35
|
+
echo "Updating docker image ${VIEWER_IMAGE}..."
|
|
36
|
+
docker pull ${VIEWER_IMAGE}
|
|
37
|
+
|
|
38
|
+
# Define test output directory
|
|
39
|
+
if [[ ! -z "$HOLADO_OUTPUT_BASEDIR" ]]; then
|
|
40
|
+
OUTPUT_DIR=${HOLADO_OUTPUT_BASEDIR}
|
|
41
|
+
else
|
|
42
|
+
OUTPUT_DIR=${HOME}/.holado/output
|
|
43
|
+
fi
|
|
44
|
+
echo "Output directory: $OUTPUT_DIR"
|
|
45
|
+
|
|
46
|
+
# Define test resources directory
|
|
47
|
+
if [[ ! -z "$HOLADO_LOCAL_RESOURCES_BASEDIR" ]]; then
|
|
48
|
+
RESOURCES_DIR=${HOLADO_LOCAL_RESOURCES_BASEDIR}
|
|
49
|
+
else
|
|
50
|
+
RESOURCES_DIR=${HOME}/.holado/resources
|
|
51
|
+
fi
|
|
52
|
+
echo "Resources directory: $RESOURCES_DIR"
|
|
53
|
+
|
|
54
|
+
# Make dirs
|
|
55
|
+
if [ ! -d ${OUTPUT_DIR} ]; then
|
|
56
|
+
echo "Create output directory: ${OUTPUT_DIR}"
|
|
57
|
+
mkdir -p ${OUTPUT_DIR}
|
|
58
|
+
fi
|
|
59
|
+
if [ ! -d ${RESOURCES_DIR} ]; then
|
|
60
|
+
echo "Create resources directory: ${RESOURCES_DIR}"
|
|
61
|
+
mkdir -p ${RESOURCES_DIR}
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
# Define container network
|
|
65
|
+
if [ "$HOLADO_USE_LOCALHOST" = True ]; then
|
|
66
|
+
NETWORK_DEF_COMMAND="--network=host"
|
|
67
|
+
else
|
|
68
|
+
if [[ ! -z "$HOLADO_NETWORK" ]]; then
|
|
69
|
+
NETWORK_DEF_COMMAND="--network $HOLADO_NETWORK"
|
|
70
|
+
else
|
|
71
|
+
NETWORK_DEF_COMMAND=""
|
|
72
|
+
fi
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
# Define port to use
|
|
76
|
+
if [[ -z "$HOLADO_DOCKER_VIEWER_PORT" ]]; then
|
|
77
|
+
HOLADO_DOCKER_VIEWER_PORT=8000
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# Docker run
|
|
82
|
+
if [[ -z "$HOLADO_DOCKER_VIEWER_NAME" ]]; then
|
|
83
|
+
HOLADO_DOCKER_VIEWER_NAME=holado_docker_VIEWER
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
echo
|
|
87
|
+
echo "Running Docker VIEWER (docker name: ${HOLADO_DOCKER_VIEWER_NAME})..."
|
|
88
|
+
echo " port: ${HOLADO_DOCKER_VIEWER_PORT}"
|
|
89
|
+
#echo " NETWORK_DEF_COMMAND=${NETWORK_DEF_COMMAND}"
|
|
90
|
+
echo
|
|
91
|
+
docker run --rm --user root --name ${HOLADO_DOCKER_VIEWER_NAME} \
|
|
92
|
+
--privileged -v /var/run/docker.sock:/var/run/docker.sock \
|
|
93
|
+
-v "${OUTPUT_DIR}":/output \
|
|
94
|
+
-v "${RESOURCES_DIR}":/resources \
|
|
95
|
+
-e HOLADO_OUTPUT_BASEDIR=/output \
|
|
96
|
+
-e HOLADO_LOCAL_RESOURCES_BASEDIR=/resources \
|
|
97
|
+
-e HOLADO_DOCKER_VIEWER_PORT=${HOLADO_DOCKER_VIEWER_PORT} \
|
|
98
|
+
${NETWORK_DEF_COMMAND} \
|
|
99
|
+
-p ${HOLADO_DOCKER_VIEWER_PORT}:${HOLADO_DOCKER_VIEWER_PORT} \
|
|
100
|
+
${VIEWER_IMAGE}
|
|
101
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
#################################################
|
|
3
|
+
# HolAdo (Holistic Automation do)
|
|
4
|
+
#
|
|
5
|
+
# (C) Copyright 2021-2025 by Eric Klumpp
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
#
|
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
# The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
|
|
12
|
+
#################################################
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
#################################################
|
|
16
|
+
# GOAL: Tools when using a clone of HolAdo project.
|
|
17
|
+
#
|
|
18
|
+
# This file contains methods usefull to initialize environments using a clone of HolAdo project.
|
|
19
|
+
#
|
|
20
|
+
# USAGE:
|
|
21
|
+
# - Copy this file in projects using HolAdo.
|
|
22
|
+
# - Define environment variable HOLADO_PATH with path to cloned HolAdo project.
|
|
23
|
+
# If HOLADO_PATH is defined, sources of cloned HolAdo project are used, else installed holado package is used.
|
|
24
|
+
#################################################
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
import os
|
|
29
|
+
import sys
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def insert_sys_path(path, index=0):
|
|
33
|
+
"""Insert a path in sys.path if it doesn't already exists.
|
|
34
|
+
"""
|
|
35
|
+
if path not in sys.path:
|
|
36
|
+
sys.path.insert(index, path)
|
|
37
|
+
|
|
38
|
+
def insert_sys_paths(list_paths, index=0):
|
|
39
|
+
"""Insert a list of path in sys.path if it doesn't already exists.
|
|
40
|
+
"""
|
|
41
|
+
if list_paths:
|
|
42
|
+
for path in list_paths:
|
|
43
|
+
insert_sys_path(path, index=index)
|
|
44
|
+
|
|
45
|
+
def insert_holado_source_paths(with_test_behave=True):
|
|
46
|
+
"""Insert in sys.path all HolAdo source paths.
|
|
47
|
+
If environment variable HOLADO_PATH is defined with path to HolAdo project, following paths are inserted in sys.path:
|
|
48
|
+
- HOLADO_PATH/src: path to holado modules sources
|
|
49
|
+
- HOLADO_PATH/tests/behave (if with_test_behave==True): path to holado test sources, needed by testing solutions
|
|
50
|
+
"""
|
|
51
|
+
holado_path = os.getenv('HOLADO_PATH')
|
|
52
|
+
if holado_path is None:
|
|
53
|
+
try:
|
|
54
|
+
import holado # @UnusedImport
|
|
55
|
+
except Exception as exc:
|
|
56
|
+
if "No module named" in str(exc):
|
|
57
|
+
raise Exception(f"If environment variable HOLADO_PATH is not defined with path to HolAdo project, 'holado' python package must be installed")
|
|
58
|
+
else:
|
|
59
|
+
raise exc
|
|
60
|
+
else:
|
|
61
|
+
# holado is installed, and all sources are already accessible
|
|
62
|
+
pass
|
|
63
|
+
else:
|
|
64
|
+
print(f"Using HolAdo project installed in '{holado_path}'")
|
|
65
|
+
# import traceback
|
|
66
|
+
# print("".join(traceback.format_list(traceback.extract_stack())))
|
|
67
|
+
# insert_sys_path(holado_path)
|
|
68
|
+
insert_sys_path(os.path.join(holado_path, "src"))
|
|
69
|
+
if with_test_behave:
|
|
70
|
+
insert_sys_path(os.path.join(holado_path, "tests", "behave"))
|
|
71
|
+
|
|
72
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""Django's command-line utility for administrative tasks."""
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
"""Run administrative tasks."""
|
|
9
|
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rest_api.settings')
|
|
10
|
+
try:
|
|
11
|
+
from django.core.management import execute_from_command_line
|
|
12
|
+
except ImportError as exc:
|
|
13
|
+
raise ImportError(
|
|
14
|
+
"Couldn't import Django. Are you sure it's installed and "
|
|
15
|
+
"available on your PYTHONPATH environment variable? Did you "
|
|
16
|
+
"forget to activate a virtual environment?"
|
|
17
|
+
) from exc
|
|
18
|
+
execute_from_command_line(sys.argv)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if __name__ == '__main__':
|
|
22
|
+
main()
|
|
File without changes
|
holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/__init__.py
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from django.contrib.auth.models import User, Group
|
|
2
|
+
from rest_framework import serializers
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
|
6
|
+
class Meta:
|
|
7
|
+
model = User
|
|
8
|
+
fields = ['url', 'username', 'email', 'groups']
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class GroupSerializer(serializers.HyperlinkedModelSerializer):
|
|
12
|
+
class Meta:
|
|
13
|
+
model = Group
|
|
14
|
+
fields = ['url', 'name']
|
|
15
|
+
|
holado_examples/projects/server_rest/server_rest_example/rest_api/rest_api/application/views.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from django.shortcuts import render
|
|
2
|
+
from django.contrib.auth.models import User, Group
|
|
3
|
+
from rest_framework import viewsets
|
|
4
|
+
from rest_framework import permissions
|
|
5
|
+
from .serializers import UserSerializer, GroupSerializer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class UserViewSet(viewsets.ModelViewSet):
|
|
9
|
+
"""
|
|
10
|
+
API endpoint that allows users to be viewed or edited.
|
|
11
|
+
"""
|
|
12
|
+
queryset = User.objects.all().order_by('-date_joined')
|
|
13
|
+
serializer_class = UserSerializer
|
|
14
|
+
permission_classes = [permissions.IsAuthenticated]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class GroupViewSet(viewsets.ModelViewSet):
|
|
18
|
+
"""
|
|
19
|
+
API endpoint that allows groups to be viewed or edited.
|
|
20
|
+
"""
|
|
21
|
+
queryset = Group.objects.all()
|
|
22
|
+
serializer_class = GroupSerializer
|
|
23
|
+
permission_classes = [permissions.IsAuthenticated]
|
|
24
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ASGI config for server_rest_example project.
|
|
3
|
+
|
|
4
|
+
It exposes the ASGI callable as a module-level variable named ``application``.
|
|
5
|
+
|
|
6
|
+
For more information on this file, see
|
|
7
|
+
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
from django.core.asgi import get_asgi_application
|
|
13
|
+
|
|
14
|
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rest_api.settings')
|
|
15
|
+
|
|
16
|
+
application = get_asgi_application()
|