holado 0.11.2__py3-none-any.whl → 0.11.4__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-0.11.2.dist-info → holado-0.11.4.dist-info}/METADATA +2 -2
- {holado-0.11.2.dist-info → holado-0.11.4.dist-info}/RECORD +48 -14
- holado_ais/ais/ais_messages.py +2 -2
- holado_ais/tests/behave/steps/ais/ais_messages_steps.py +1 -1
- holado_core/common/resource/persisted_method_to_call_manager.py +1 -1
- holado_python/standard_library/ssl/resources/certificates/tcpbin.crt +16 -16
- holado_python/standard_library/ssl/resources/certificates/tcpbin.key +26 -26
- holado_report/report/builders/summary_by_category_report_builder.py +86 -0
- holado_report/report/report_manager.py +4 -0
- holado_test/tools/test_server/client/rest/test_server_client.py +20 -0
- holado_test/tools/test_server/server/rest/api/__init__.py +6 -5
- holado_test/tools/test_server/server/rest/openapi.yaml +11 -0
- holado_tools/__init__.py +38 -0
- holado_tools/scripts/execute_persisted_post_processes/execute_persisted_post_processes.py +36 -0
- holado_tools/scripts/execute_persisted_post_processes/execute_persisted_post_processes.sh +6 -0
- holado_tools/scripts/execute_persisted_post_processes/initialize_holado.py +62 -0
- holado_tools/tests/behave/steps/__init__.py +16 -0
- holado_tools/tests/behave/steps/tools/host_controller/client_steps.py +97 -0
- holado_tools/tools/host_controller/client/rest/host_controller_client.py +168 -0
- holado_tools/tools/host_controller/server/Dockerfile +60 -0
- holado_tools/tools/host_controller/server/grpc/README +2 -0
- holado_tools/tools/host_controller/server/grpc/__init__.py +26 -0
- holado_tools/tools/host_controller/server/grpc/proto/compile_proto.py +60 -0
- holado_tools/tools/host_controller/server/grpc/proto/definitions/docker_controler.proto +63 -0
- holado_tools/tools/host_controller/server/requirements.txt +2 -0
- holado_tools/tools/host_controller/server/rest/README +2 -0
- holado_tools/tools/host_controller/server/rest/api/__init__.py +24 -0
- holado_tools/tools/host_controller/server/rest/api/config.py +57 -0
- holado_tools/tools/host_controller/server/rest/api/docker/__init__.py +40 -0
- holado_tools/tools/host_controller/server/rest/api/docker/container.py +55 -0
- holado_tools/tools/host_controller/server/rest/api/os.py +47 -0
- holado_tools/tools/host_controller/server/rest/initialize_holado.py +72 -0
- holado_tools/tools/host_controller/server/rest/openapi.yaml +276 -0
- holado_tools/tools/host_controller/server/rest/run.py +31 -0
- holado_tools/tools/host_controller/server/run_host_controller_in_docker.sh +107 -0
- holado_tools/tools/host_viewer/client/rest/host_viewer_client.py +96 -0
- holado_tools/tools/host_viewer/server/Dockerfile +60 -0
- holado_tools/tools/host_viewer/server/requirements.txt +2 -0
- holado_tools/tools/host_viewer/server/rest/README +2 -0
- holado_tools/tools/host_viewer/server/rest/api/__init__.py +24 -0
- holado_tools/tools/host_viewer/server/rest/api/docker/__init__.py +40 -0
- holado_tools/tools/host_viewer/server/rest/initialize_holado.py +72 -0
- holado_tools/tools/host_viewer/server/rest/openapi.yaml +113 -0
- holado_tools/tools/host_viewer/server/rest/run.py +31 -0
- holado_tools/tools/host_viewer/server/run_host_viewer_in_docker.sh +107 -0
- test_holado/environment.py +7 -0
- {holado-0.11.2.dist-info → holado-0.11.4.dist-info}/WHEEL +0 -0
- {holado-0.11.2.dist-info → holado-0.11.4.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
|
|
16
|
+
from .tools.host_controller.client_steps import *
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
|
|
16
|
+
from holado.common.context.session_context import SessionContext
|
|
17
|
+
from holado_test.behave.behave import * # @UnusedWildImport
|
|
18
|
+
import logging
|
|
19
|
+
from holado_test.scenario.step_tools import StepTools
|
|
20
|
+
from holado_test.behave.scenario.behave_step_tools import BehaveStepTools
|
|
21
|
+
from holado_value.common.tables.converters.value_table_converter import ValueTableConverter
|
|
22
|
+
from holado_tools.tools.host_controller.client.rest.host_controller_client import HostControllerClient
|
|
23
|
+
|
|
24
|
+
logger = logging.getLogger(__name__)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def __get_scenario_context():
|
|
28
|
+
return SessionContext.instance().get_scenario_context()
|
|
29
|
+
|
|
30
|
+
def __get_variable_manager():
|
|
31
|
+
return __get_scenario_context().get_variable_manager()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@Given(r"(?P<var_name>{Variable}) = new Host Controller client")
|
|
35
|
+
def step_impl(context, var_name):
|
|
36
|
+
var_name = StepTools.evaluate_variable_name(var_name)
|
|
37
|
+
table = BehaveStepTools.get_step_table(context)
|
|
38
|
+
if table is not None:
|
|
39
|
+
kwargs = ValueTableConverter.convert_name_value_table_2_dict(table)
|
|
40
|
+
else:
|
|
41
|
+
kwargs = {}
|
|
42
|
+
|
|
43
|
+
res = HostControllerClient.new_client(**kwargs)
|
|
44
|
+
|
|
45
|
+
__get_variable_manager().register_variable(var_name, res)
|
|
46
|
+
|
|
47
|
+
@Step(r"(?P<var_name>{Variable}) = list containers \(Host Controller client: (?P<var_client>{Variable})\)")
|
|
48
|
+
def step_impl(context, var_name, var_client):
|
|
49
|
+
var_name = StepTools.evaluate_variable_name(var_name)
|
|
50
|
+
client = StepTools.evaluate_variable_value(var_client)
|
|
51
|
+
|
|
52
|
+
res = client.get_containers_status()
|
|
53
|
+
|
|
54
|
+
__get_variable_manager().register_variable(var_name, res)
|
|
55
|
+
|
|
56
|
+
@Step(r"(?P<var_name>{Variable}) = get information on container (?P<name>{Str}) \(Host Controller client: (?P<var_client>{Variable})\)")
|
|
57
|
+
def step_impl(context, var_name, name, var_client):
|
|
58
|
+
var_name = StepTools.evaluate_variable_name(var_name)
|
|
59
|
+
name = StepTools.evaluate_scenario_parameter(name)
|
|
60
|
+
client = StepTools.evaluate_variable_value(var_client)
|
|
61
|
+
|
|
62
|
+
res = client.get_container_info(name)
|
|
63
|
+
|
|
64
|
+
__get_variable_manager().register_variable(var_name, res)
|
|
65
|
+
|
|
66
|
+
@Step(r"(?:(?P<or_start_str>start or ))?restart container (?P<name>{Str}) \(Host Controller client: (?P<var_client>{Variable})\)")
|
|
67
|
+
def step_impl(context, or_start_str, name, var_client):
|
|
68
|
+
or_start = or_start_str is not None
|
|
69
|
+
name = StepTools.evaluate_scenario_parameter(name)
|
|
70
|
+
client = StepTools.evaluate_variable_value(var_client)
|
|
71
|
+
|
|
72
|
+
client.restart_container(name, start_if_gone=or_start)
|
|
73
|
+
|
|
74
|
+
@Step(r"start container (?P<name>{Str}) \(Host Controller client: (?P<var_client>{Variable})\)")
|
|
75
|
+
def step_impl(context, name, var_client):
|
|
76
|
+
name = StepTools.evaluate_scenario_parameter(name)
|
|
77
|
+
client = StepTools.evaluate_variable_value(var_client)
|
|
78
|
+
|
|
79
|
+
client.start_container(name)
|
|
80
|
+
|
|
81
|
+
@Step(r"stop container (?P<name>{Str})(?:(?P<if_started_str> if started))? \(Host Controller client: (?P<var_client>{Variable})\)")
|
|
82
|
+
def step_impl(context, name, if_started_str, var_client):
|
|
83
|
+
name = StepTools.evaluate_scenario_parameter(name)
|
|
84
|
+
if_started = if_started_str is not None
|
|
85
|
+
client = StepTools.evaluate_variable_value(var_client)
|
|
86
|
+
|
|
87
|
+
client.stop_container(name, raise_if_gone=not if_started)
|
|
88
|
+
|
|
89
|
+
@Step(r"wait container (?P<name>{Str})(?:(?P<if_started_str> if started))? \(Host Controller client: (?P<var_client>{Variable})\)")
|
|
90
|
+
def step_impl(context, name, if_started_str, var_client):
|
|
91
|
+
name = StepTools.evaluate_scenario_parameter(name)
|
|
92
|
+
if_started = if_started_str is not None
|
|
93
|
+
client = StepTools.evaluate_variable_value(var_client)
|
|
94
|
+
|
|
95
|
+
client.wait_container(name, raise_if_gone=not if_started)
|
|
96
|
+
|
|
97
|
+
|
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
from holado_core.common.handlers.wait import WaitFuncResult
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class HostControllerClient(RestClient):
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def new_client(cls, use_localhost=undefined_argument, **kwargs):
|
|
30
|
+
if 'name' not in kwargs:
|
|
31
|
+
kwargs['name'] = None
|
|
32
|
+
if 'url' not in kwargs:
|
|
33
|
+
if use_localhost is undefined_argument:
|
|
34
|
+
env_use = os.getenv("HOLADO_USE_LOCALHOST", False)
|
|
35
|
+
use_localhost = Converter.is_boolean(env_use) and Converter.to_boolean(env_use)
|
|
36
|
+
|
|
37
|
+
url = os.getenv("HOLADO_HOST_CONTROLLER_URL", undefined_value)
|
|
38
|
+
if url is undefined_value:
|
|
39
|
+
scheme = kwargs.get('scheme', undefined_value)
|
|
40
|
+
if scheme is undefined_value:
|
|
41
|
+
scheme = os.getenv("HOLADO_HOST_CONTROLLER_SCHEME", "http")
|
|
42
|
+
host = kwargs.get('host', undefined_value)
|
|
43
|
+
if host is undefined_value:
|
|
44
|
+
host = "localhost" if use_localhost else os.getenv("HOLADO_HOST_CONTROLLER_HOST", "holado_host_controller")
|
|
45
|
+
port = kwargs.get('port', undefined_value)
|
|
46
|
+
if port is undefined_value:
|
|
47
|
+
if use_localhost:
|
|
48
|
+
port = os.getenv("HOLADO_HOST_CONTROLLER_HOSTPORT", 51231)
|
|
49
|
+
else:
|
|
50
|
+
port = os.getenv("HOLADO_HOST_CONTROLLER_PORT", 51231)
|
|
51
|
+
|
|
52
|
+
if port is None:
|
|
53
|
+
url = f"{scheme}://{host}"
|
|
54
|
+
else:
|
|
55
|
+
url = f"{scheme}://{host}:{port}"
|
|
56
|
+
kwargs['url'] = url
|
|
57
|
+
|
|
58
|
+
manager = RestManager(default_client_class=HostControllerClient)
|
|
59
|
+
res = manager.new_client(**kwargs)
|
|
60
|
+
|
|
61
|
+
return res
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def __init__(self, name, url, headers=None):
|
|
65
|
+
super().__init__(name, url, headers)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Monitoring
|
|
69
|
+
|
|
70
|
+
def is_healthy(self):
|
|
71
|
+
try:
|
|
72
|
+
response = self.get(f"health")
|
|
73
|
+
return response.status_code == 200
|
|
74
|
+
except:
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
def wait_is_healthy(self, timeout_sec=300, do_raise_on_timeout=True):
|
|
78
|
+
logger.info("Waiting for host-controller to be healthy...")
|
|
79
|
+
wait_context = WaitFuncResult(f"wait test-server is healthy", self.is_healthy)
|
|
80
|
+
wait_context.with_timeout(timeout_sec) \
|
|
81
|
+
.with_raise_on_timeout(do_raise_on_timeout) \
|
|
82
|
+
.with_process_in_thread(False)
|
|
83
|
+
wait_context.redo_until(True)
|
|
84
|
+
wait_context.execute()
|
|
85
|
+
logger.info("host-controller is healthy")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# Common features
|
|
89
|
+
|
|
90
|
+
def get_environment_variable_value(self, var_name):
|
|
91
|
+
data = [var_name]
|
|
92
|
+
response = self.get(f"os/env", json=data)
|
|
93
|
+
return self.response_result(response, status_ok=[200])
|
|
94
|
+
|
|
95
|
+
def get_directory_filenames(self, path, extension='.yml'):
|
|
96
|
+
data = {'path':path, 'extension':extension}
|
|
97
|
+
response = self.get(f"os/ls", json=data)
|
|
98
|
+
return self.response_result(response, status_ok=[200])
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# Manage containers
|
|
102
|
+
|
|
103
|
+
def get_containers_status(self, all_=False):
|
|
104
|
+
if all_:
|
|
105
|
+
response = self.get("docker/container?all=true")
|
|
106
|
+
else:
|
|
107
|
+
response = self.get("docker/container")
|
|
108
|
+
return self.response_result(response, status_ok=[200,204])
|
|
109
|
+
|
|
110
|
+
def get_container_info(self, name, all_=False):
|
|
111
|
+
"""Get container info
|
|
112
|
+
@return container info if found, else None
|
|
113
|
+
"""
|
|
114
|
+
if all_:
|
|
115
|
+
response = self.get(f"docker/container/{name}?all=true")
|
|
116
|
+
else:
|
|
117
|
+
response = self.get(f"docker/container/{name}")
|
|
118
|
+
return self.response_result(response, status_ok=[200,204], result_on_statuses={204:None, default_value:None})
|
|
119
|
+
|
|
120
|
+
def restart_container(self, name, start_if_gone=False):
|
|
121
|
+
response = self.put(f"docker/container/{name}/restart")
|
|
122
|
+
if start_if_gone and response.status_code == 410:
|
|
123
|
+
return self.start_container(name)
|
|
124
|
+
else:
|
|
125
|
+
return self.response_result(response, status_ok=[200,204])
|
|
126
|
+
|
|
127
|
+
def start_container(self, name):
|
|
128
|
+
response = self.put(f"docker/container/{name}/start")
|
|
129
|
+
return self.response_result(response, status_ok=[200,204])
|
|
130
|
+
|
|
131
|
+
def stop_container(self, name, raise_if_gone=True):
|
|
132
|
+
response = self.put(f"docker/container/{name}/stop")
|
|
133
|
+
if not raise_if_gone and response.status_code == 410:
|
|
134
|
+
return None
|
|
135
|
+
else:
|
|
136
|
+
return self.response_result(response, status_ok=[200,204])
|
|
137
|
+
|
|
138
|
+
def wait_container(self, name, raise_if_gone=True):
|
|
139
|
+
response = self.put(f"docker/container/{name}/wait")
|
|
140
|
+
if not raise_if_gone and response.status_code == 410:
|
|
141
|
+
return None
|
|
142
|
+
else:
|
|
143
|
+
return self.response_result(response, status_ok=[200,204])
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
# Manage configuration
|
|
147
|
+
|
|
148
|
+
def update_yaml_file(self, file_path, text, with_backup=True, backup_extension='.ha_bak'):
|
|
149
|
+
data = {
|
|
150
|
+
'file_path': file_path,
|
|
151
|
+
'yaml_string': text,
|
|
152
|
+
'with_backup': with_backup,
|
|
153
|
+
'backup_extension': backup_extension
|
|
154
|
+
}
|
|
155
|
+
response = self.patch(f"config/yaml_file", json=data)
|
|
156
|
+
return self.response_result(response, status_ok=[200,204])
|
|
157
|
+
|
|
158
|
+
def restore_yaml_file(self, file_path, backup_extension='.ha_bak'):
|
|
159
|
+
data = {
|
|
160
|
+
'action': 'restore',
|
|
161
|
+
'file_path': file_path,
|
|
162
|
+
'backup_extension': backup_extension
|
|
163
|
+
}
|
|
164
|
+
response = self.put(f"config/yaml_file", json=data)
|
|
165
|
+
return self.response_result(response, status_ok=[200,204])
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
@@ -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,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,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
|
+
# import logging
|
|
15
|
+
|
|
16
|
+
# logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class HealthView(MethodView):
|
|
20
|
+
|
|
21
|
+
def get(self):
|
|
22
|
+
return {'status': 'healthy'}
|
|
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
|