holado 0.11.1__py3-none-any.whl → 0.11.3__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.

Files changed (46) hide show
  1. {holado-0.11.1.dist-info → holado-0.11.3.dist-info}/METADATA +2 -2
  2. {holado-0.11.1.dist-info → holado-0.11.3.dist-info}/RECORD +46 -12
  3. holado_context/tests/behave/steps/private/common/context_steps.py +1 -1
  4. holado_core/common/resource/persisted_data_manager.py +4 -0
  5. holado_core/common/resource/persisted_method_to_call_manager.py +13 -3
  6. holado_multitask/multithreading/context/thread_context.py +1 -1
  7. holado_scripting/__init__.py +1 -1
  8. holado_test/behave/behave_manager.py +3 -0
  9. holado_test/common/context/feature_context.py +1 -1
  10. holado_test/common/context/scenario_context.py +1 -1
  11. holado_tools/__init__.py +38 -0
  12. holado_tools/scripts/execute_persisted_post_processes/execute_persisted_post_processes.py +36 -0
  13. holado_tools/scripts/execute_persisted_post_processes/execute_persisted_post_processes.sh +6 -0
  14. holado_tools/scripts/execute_persisted_post_processes/initialize_holado.py +62 -0
  15. holado_tools/tests/behave/steps/__init__.py +16 -0
  16. holado_tools/tests/behave/steps/tools/host_controller/client_steps.py +97 -0
  17. holado_tools/tools/host_controller/client/rest/host_controller_client.py +146 -0
  18. holado_tools/tools/host_controller/server/Dockerfile +60 -0
  19. holado_tools/tools/host_controller/server/grpc/README +2 -0
  20. holado_tools/tools/host_controller/server/grpc/__init__.py +26 -0
  21. holado_tools/tools/host_controller/server/grpc/proto/compile_proto.py +60 -0
  22. holado_tools/tools/host_controller/server/grpc/proto/definitions/docker_controler.proto +63 -0
  23. holado_tools/tools/host_controller/server/requirements.txt +2 -0
  24. holado_tools/tools/host_controller/server/rest/README +2 -0
  25. holado_tools/tools/host_controller/server/rest/api/__init__.py +24 -0
  26. holado_tools/tools/host_controller/server/rest/api/config.py +57 -0
  27. holado_tools/tools/host_controller/server/rest/api/docker/__init__.py +40 -0
  28. holado_tools/tools/host_controller/server/rest/api/docker/container.py +55 -0
  29. holado_tools/tools/host_controller/server/rest/api/os.py +47 -0
  30. holado_tools/tools/host_controller/server/rest/initialize_holado.py +72 -0
  31. holado_tools/tools/host_controller/server/rest/openapi.yaml +265 -0
  32. holado_tools/tools/host_controller/server/rest/run.py +31 -0
  33. holado_tools/tools/host_controller/server/run_host_controller_in_docker.sh +107 -0
  34. holado_tools/tools/host_viewer/client/rest/host_viewer_client.py +96 -0
  35. holado_tools/tools/host_viewer/server/Dockerfile +60 -0
  36. holado_tools/tools/host_viewer/server/requirements.txt +2 -0
  37. holado_tools/tools/host_viewer/server/rest/README +2 -0
  38. holado_tools/tools/host_viewer/server/rest/api/__init__.py +22 -0
  39. holado_tools/tools/host_viewer/server/rest/api/docker/__init__.py +40 -0
  40. holado_tools/tools/host_viewer/server/rest/initialize_holado.py +72 -0
  41. holado_tools/tools/host_viewer/server/rest/openapi.yaml +102 -0
  42. holado_tools/tools/host_viewer/server/rest/run.py +31 -0
  43. holado_tools/tools/host_viewer/server/run_host_viewer_in_docker.sh +107 -0
  44. test_holado/features/Configuration/Actions/execute_persisted_post_processes.feature +13 -0
  45. {holado-0.11.1.dist-info → holado-0.11.3.dist-info}/WHEEL +0 -0
  46. {holado-0.11.1.dist-info → holado-0.11.3.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,146 @@
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
+ from holado.common.handlers.undefined import default_value, undefined_argument,\
17
+ undefined_value
18
+ import os
19
+ from holado_core.common.tools.converters.converter import Converter
20
+ from holado_rest.api.rest.rest_manager import RestManager
21
+
22
+ logger = logging.getLogger(__name__)
23
+
24
+
25
+ class HostControllerClient(RestClient):
26
+
27
+ @classmethod
28
+ def new_client(cls, use_localhost=undefined_argument, **kwargs):
29
+ if 'name' not in kwargs:
30
+ kwargs['name'] = None
31
+ if 'url' not in kwargs:
32
+ if use_localhost is undefined_argument:
33
+ env_use = os.getenv("HOLADO_USE_LOCALHOST", False)
34
+ use_localhost = Converter.is_boolean(env_use) and Converter.to_boolean(env_use)
35
+
36
+ url = os.getenv("HOLADO_HOST_CONTROLLER_URL", undefined_value)
37
+ if url is undefined_value:
38
+ scheme = kwargs.get('scheme', undefined_value)
39
+ if scheme is undefined_value:
40
+ scheme = os.getenv("HOLADO_HOST_CONTROLLER_SCHEME", "http")
41
+ host = kwargs.get('host', undefined_value)
42
+ if host is undefined_value:
43
+ host = "localhost" if use_localhost else os.getenv("HOLADO_HOST_CONTROLLER_HOST", "holado_host_controller")
44
+ port = kwargs.get('port', undefined_value)
45
+ if port is undefined_value:
46
+ if use_localhost:
47
+ port = os.getenv("HOLADO_HOST_CONTROLLER_HOSTPORT", 51231)
48
+ else:
49
+ port = os.getenv("HOLADO_HOST_CONTROLLER_PORT", 51231)
50
+
51
+ if port is None:
52
+ url = f"{scheme}://{host}"
53
+ else:
54
+ url = f"{scheme}://{host}:{port}"
55
+ kwargs['url'] = url
56
+
57
+ manager = RestManager(default_client_class=HostControllerClient)
58
+ res = manager.new_client(**kwargs)
59
+
60
+ return res
61
+
62
+
63
+ def __init__(self, name, url, headers=None):
64
+ super().__init__(name, url, headers)
65
+
66
+ # Common features
67
+
68
+ def get_environment_variable_value(self, var_name):
69
+ data = [var_name]
70
+ response = self.get(f"os/env", json=data)
71
+ return self.response_result(response, status_ok=[200])
72
+
73
+ def get_directory_filenames(self, path, extension='.yml'):
74
+ data = {'path':path, 'extension':extension}
75
+ response = self.get(f"os/ls", json=data)
76
+ return self.response_result(response, status_ok=[200])
77
+
78
+
79
+ # Manage containers
80
+
81
+ def get_containers_status(self, all_=False):
82
+ if all_:
83
+ response = self.get("docker/container?all=true")
84
+ else:
85
+ response = self.get("docker/container")
86
+ return self.response_result(response, status_ok=[200,204])
87
+
88
+ def get_container_info(self, name, all_=False):
89
+ """Get container info
90
+ @return container info if found, else None
91
+ """
92
+ if all_:
93
+ response = self.get(f"docker/container/{name}?all=true")
94
+ else:
95
+ response = self.get(f"docker/container/{name}")
96
+ return self.response_result(response, status_ok=[200,204], result_on_statuses={204:None, default_value:None})
97
+
98
+ def restart_container(self, name, start_if_gone=False):
99
+ response = self.put(f"docker/container/{name}/restart")
100
+ if start_if_gone and response.status_code == 410:
101
+ return self.start_container(name)
102
+ else:
103
+ return self.response_result(response, status_ok=[200,204])
104
+
105
+ def start_container(self, name):
106
+ response = self.put(f"docker/container/{name}/start")
107
+ return self.response_result(response, status_ok=[200,204])
108
+
109
+ def stop_container(self, name, raise_if_gone=True):
110
+ response = self.put(f"docker/container/{name}/stop")
111
+ if not raise_if_gone and response.status_code == 410:
112
+ return None
113
+ else:
114
+ return self.response_result(response, status_ok=[200,204])
115
+
116
+ def wait_container(self, name, raise_if_gone=True):
117
+ response = self.put(f"docker/container/{name}/wait")
118
+ if not raise_if_gone and response.status_code == 410:
119
+ return None
120
+ else:
121
+ return self.response_result(response, status_ok=[200,204])
122
+
123
+
124
+ # Manage configuration
125
+
126
+ def update_yaml_file(self, file_path, text, with_backup=True, backup_extension='.ha_bak'):
127
+ data = {
128
+ 'file_path': file_path,
129
+ 'yaml_string': text,
130
+ 'with_backup': with_backup,
131
+ 'backup_extension': backup_extension
132
+ }
133
+ response = self.patch(f"config/yaml_file", json=data)
134
+ return self.response_result(response, status_ok=[200,204])
135
+
136
+ def restore_yaml_file(self, file_path, backup_extension='.ha_bak'):
137
+ data = {
138
+ 'action': 'restore',
139
+ 'file_path': file_path,
140
+ 'backup_extension': backup_extension
141
+ }
142
+ response = self.put(f"config/yaml_file", json=data)
143
+ return self.response_result(response, status_ok=[200,204])
144
+
145
+
146
+
@@ -0,0 +1,60 @@
1
+ ### Build
2
+
3
+ #FROM python:3.12.9-alpine3.21 AS build
4
+ #FROM python:3.12.11-alpine3.22 AS build
5
+ FROM python:3.12.12-alpine3.22 AS build
6
+
7
+ # Install to build python requirements
8
+ RUN apk update \
9
+ && apk --no-cache --update add build-base \
10
+ && apk --update add alpine-sdk \
11
+ && apk add libffi-dev
12
+
13
+ # Create user
14
+ RUN addgroup appuser \
15
+ && adduser -G appuser -s /bin/bash -D appuser
16
+
17
+ # Create /code folder
18
+ RUN mkdir /code \
19
+ && chown -R appuser:appuser /code
20
+
21
+ # Switch to user appuser
22
+ USER appuser
23
+
24
+ # Create python venv and install requirements
25
+ COPY --chown=appuser ./requirements.txt /code/host_controller/requirements.txt
26
+ WORKDIR /code/host_controller
27
+ RUN python -m venv /code/env \
28
+ && source /code/env/bin/activate \
29
+ && pip install --no-cache-dir -r requirements.txt
30
+
31
+
32
+
33
+ ### Runtime
34
+
35
+ #FROM python:3.12.9-alpine3.21 AS runtime
36
+ #FROM python:3.12.11-alpine3.22 AS runtime
37
+ FROM python:3.12.12-alpine3.22 AS runtime
38
+
39
+ # Add tools
40
+ RUN apk --no-cache add bash \
41
+ && apk --no-cache add nano \
42
+ && apk --no-cache add curl
43
+
44
+ # Create and switch to user appuser as in build
45
+ RUN addgroup appuser \
46
+ && adduser -G appuser -s /bin/bash -D appuser
47
+ USER appuser
48
+
49
+ # Copy /code from build
50
+ COPY --chown=appuser --from=build /code /code
51
+
52
+ # Copy host controller sources
53
+ COPY --chown=appuser ./rest /code/host_controller
54
+
55
+ # Activate permanently python venv
56
+ ENV PATH=/code/env/bin:$PATH
57
+
58
+ WORKDIR /code/host_controller
59
+ CMD ["sh", "-c", "uvicorn run:app --host 0.0.0.0 --port $HOLADO_HOST_CONTROLLER_PORT"]
60
+
@@ -0,0 +1,2 @@
1
+ WARNING: The content of this folder is not working yet
2
+ Use the REST version of Host Controller that is in ../rest folder
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ #################################################
4
+ # HolAdo (Holistic Automation do)
5
+ #
6
+ # (C) Copyright 2021-2025 by Eric Klumpp
7
+ #
8
+ # 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:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+
12
+ # 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.
13
+ #################################################
14
+
15
+ import os
16
+ import sys
17
+
18
+
19
+ # Add path to compiled proto files used by docker controler classes
20
+ here = os.path.abspath(os.path.dirname(__file__))
21
+ compiled_proto_path = os.path.normpath(os.path.join(here, "proto", "generated"))
22
+ if compiled_proto_path not in sys.path:
23
+ sys.path.append(compiled_proto_path)
24
+
25
+
26
+
@@ -0,0 +1,60 @@
1
+ import os
2
+ import sys
3
+ import shutil
4
+
5
+ here = os.path.abspath(os.path.dirname(__file__))
6
+
7
+ holado_src_path = os.path.normpath(os.path.join(here, "..", "..", "..", ".."))
8
+ holado_path = os.path.normpath(os.path.join(holado_src_path, ".."))
9
+ sys.path.insert(0, holado_src_path)
10
+ print(f"Inserted path: {holado_src_path}")
11
+
12
+ from holado_core.common.tools.path_manager import PathManager
13
+ # from holado_protobuf.ipc.protobuf.protobuf_compiler import ProtobufCompiler
14
+ from holado_grpc.ipc.rpc.grpc_compiler import GRpcCompiler
15
+
16
+ # def compile_protobuf_proto(remove_destination=True):
17
+ # # Define protoc path
18
+ # protoc_exe_path = os.path.join(holado_path, "dependencies", "protoc", "protoc-23.4-linux-x86_64", "bin", "protoc")
19
+ #
20
+ # # Define proto and generated paths
21
+ # proto_path = os.path.join(here, "definitions")
22
+ # destination_path = os.path.join(here, "generated")
23
+ #
24
+ # # Remove existing destination
25
+ # if remove_destination and os.path.exists(destination_path) and os.path.isdir(destination_path):
26
+ # shutil.rmtree(destination_path)
27
+ #
28
+ # protoc = ProtobufCompiler()
29
+ # protoc.protoc_exe_path = protoc_exe_path
30
+ #
31
+ # protoc.register_proto_path(os.path.join(proto_path, "xxx"), os.path.join(destination_path, "xxx"), os.path.join(proto_path, "xxx", "yyy"))
32
+ #
33
+ # protoc.compile_all_proto()
34
+
35
+ def compile_grpc_proto(remove_destination=True):
36
+ # Define proto and generated paths
37
+ proto_path = os.path.join(here, "definitions")
38
+ destination_path = os.path.join(here, "generated")
39
+
40
+ # Remove existing destination
41
+ if remove_destination and os.path.exists(destination_path) and os.path.isdir(destination_path):
42
+ if destination_path != proto_path:
43
+ shutil.rmtree(destination_path)
44
+ else:
45
+ path_manager = PathManager()
46
+ glob_pattern = os.path.join(destination_path, "*.py")
47
+ path_manager.remove_paths(glob_pattern)
48
+
49
+ protoc = GRpcCompiler()
50
+
51
+ protoc.register_proto_path(proto_path, destination_path)
52
+
53
+ protoc.compile_all_proto()
54
+
55
+ if __name__ == "__main__":
56
+ # compile_protobuf_proto()
57
+ # compile_grpc_proto(remove_destination=False)
58
+ compile_grpc_proto()
59
+
60
+
@@ -0,0 +1,63 @@
1
+ syntax = "proto3";
2
+
3
+ package docker_controler;
4
+
5
+
6
+ // DockerControlerService represents the querying service provided by docker controler.
7
+ service DockerControlerService {
8
+ // Get all container names.
9
+ rpc GetAllContainerNames(GetAllContainerNamesRequest) returns (GetAllContainerNamesResponse) {};
10
+
11
+ // Start a container.
12
+ rpc StartContainer(StartContainerRequest) returns (StartContainerResponse) {};
13
+
14
+ // Stop a container.
15
+ rpc StopContainer(StopContainerRequest) returns (StopContainerResponse) {};
16
+
17
+ // Restart a container.
18
+ rpc RestartContainer(RestartContainerRequest) returns (RestartContainerResponse) {};
19
+ }
20
+
21
+
22
+ // Request and Response of DockerControlerService.GetAllContainerNames.
23
+ message GetAllContainerNamesRequest {
24
+ }
25
+
26
+ message GetAllContainerNamesResponse {
27
+ // List of names of containers existing on server.
28
+ repeated string container_names = 1;
29
+ }
30
+
31
+ // Request and Response of DockerControlerService.StartContainer.
32
+ message StartContainerRequest {
33
+ // Container name.
34
+ string name = 1;
35
+ }
36
+
37
+ message StartContainerResponse {
38
+ // Container status after request
39
+ string container_status = 1;
40
+ }
41
+
42
+ // Request and Response of DockerControlerService.StopContainer.
43
+ message StopContainerRequest {
44
+ // Container name.
45
+ string name = 1;
46
+ }
47
+
48
+ message StopContainerResponse {
49
+ // Container status after request
50
+ string container_status = 1;
51
+ }
52
+
53
+ // Request and Response of DockerControlerService.RestartContainer.
54
+ message RestartContainerRequest {
55
+ // Container name.
56
+ string name = 1;
57
+ }
58
+
59
+ message RestartContainerResponse {
60
+ // Container status after request
61
+ string container_status = 1;
62
+ }
63
+
@@ -0,0 +1,2 @@
1
+ # HolAdo framework
2
+ holado[api-connexion,docker,ssl,yaml]
@@ -0,0 +1,2 @@
1
+ REST API specification is described in openapi.yaml.
2
+ If Host Controller is running, the specification can be displayed with path /ui (ex: http://127.0.0.1:8000/ui).
@@ -0,0 +1,24 @@
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
+
@@ -0,0 +1,57 @@
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
+ from holado_yaml.yaml.yaml_manager import YAMLManager
16
+
17
+ def _get_session_context():
18
+ return SessionContext.instance()
19
+
20
+
21
+ class YamlFileView(MethodView):
22
+
23
+ def get(self, body: dict):
24
+ file_path = body['file_path']
25
+
26
+ with open(file_path, 'rt') as fin:
27
+ res = fin.read()
28
+
29
+ return res
30
+
31
+ def patch(self, body: dict):
32
+ file_path = body['file_path']
33
+ yaml_string = body['yaml_string']
34
+ with_backup = body['with_backup']
35
+ backup_extension = body['backup_extension']
36
+
37
+ data = YAMLManager.load_string(yaml_string)
38
+ res = YAMLManager.update_file(file_path, data, with_backup=with_backup, backup_extension=backup_extension)
39
+
40
+ return res
41
+
42
+ def put(self, body: list):
43
+ action = body['action']
44
+ file_path = body['file_path']
45
+ backup_extension = body['backup_extension']
46
+
47
+ if action == 'restore':
48
+ res = YAMLManager.restore_file(file_path, backup_extension=backup_extension)
49
+ else:
50
+ return f"Unmanaged action '{action}'", 400
51
+
52
+ return res
53
+
54
+
55
+
56
+
57
+
@@ -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,55 @@
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
+
16
+ def _get_session_context():
17
+ return SessionContext.instance()
18
+
19
+
20
+ class RestartView(MethodView):
21
+
22
+ def put(self, name, body: dict):
23
+ if not _get_session_context().docker_client.has_container(name):
24
+ return f"Container '{name}' doesn't exist", 410
25
+
26
+ res = _get_session_context().docker_client.restart_container(name, wait_running=False)
27
+ return res
28
+
29
+ class StartView(MethodView):
30
+
31
+ def put(self, name, body: dict):
32
+ if not _get_session_context().docker_client.has_container(name, all_=True):
33
+ return f"Container '{name}' doesn't exist", 410
34
+
35
+ res = _get_session_context().docker_client.start_container(name, wait_running=False)
36
+ return res
37
+
38
+ class StopView(MethodView):
39
+
40
+ def put(self, name, body: dict):
41
+ if not _get_session_context().docker_client.has_container(name):
42
+ return f"Container '{name}' doesn't exist", 410
43
+
44
+ res = _get_session_context().docker_client.stop_container(name)
45
+ return res
46
+
47
+ class WaitView(MethodView):
48
+
49
+ def put(self, name, body: dict):
50
+ if not _get_session_context().docker_client.has_container(name):
51
+ return f"Container '{name}' doesn't exist", 410
52
+
53
+ res = _get_session_context().docker_client.get_container(name).wait()
54
+ return res
55
+
@@ -0,0 +1,47 @@
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 os
16
+
17
+ def _get_session_context():
18
+ return SessionContext.instance()
19
+
20
+
21
+ class EnvView(MethodView):
22
+
23
+ def get(self, body: list):
24
+ res = [os.getenv(name) for name in body]
25
+ return res
26
+
27
+
28
+ class LsView(MethodView):
29
+
30
+ def get(self, body: dict):
31
+ dir_path = body['path']
32
+ extension = body.get('extension', None)
33
+
34
+ if not os.path.exists(dir_path) or not os.path.isdir(dir_path):
35
+ return f"Directory '{dir_path}' doesn't exist", 406
36
+
37
+ res = []
38
+ for filename in os.listdir(dir_path):
39
+ if extension is not None and not filename.endswith(extension):
40
+ continue
41
+ if os.path.isfile(os.path.join(dir_path, filename)):
42
+ res.append(filename)
43
+
44
+ return res
45
+
46
+
47
+
@@ -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
+