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.
- {holado-0.11.1.dist-info → holado-0.11.3.dist-info}/METADATA +2 -2
- {holado-0.11.1.dist-info → holado-0.11.3.dist-info}/RECORD +46 -12
- holado_context/tests/behave/steps/private/common/context_steps.py +1 -1
- holado_core/common/resource/persisted_data_manager.py +4 -0
- holado_core/common/resource/persisted_method_to_call_manager.py +13 -3
- holado_multitask/multithreading/context/thread_context.py +1 -1
- holado_scripting/__init__.py +1 -1
- holado_test/behave/behave_manager.py +3 -0
- holado_test/common/context/feature_context.py +1 -1
- holado_test/common/context/scenario_context.py +1 -1
- 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 +146 -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 +265 -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 +22 -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 +102 -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/features/Configuration/Actions/execute_persisted_post_processes.feature +13 -0
- {holado-0.11.1.dist-info → holado-0.11.3.dist-info}/WHEEL +0 -0
- {holado-0.11.1.dist-info → holado-0.11.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
openapi: "3.0.0"
|
|
2
|
+
info:
|
|
3
|
+
version: "1"
|
|
4
|
+
title: "Host Controller API"
|
|
5
|
+
description: |
|
|
6
|
+
API to process some host actions from anywhere on the network.
|
|
7
|
+
In a microservice architecture, the host-controller can be run in a docker with special privileges,
|
|
8
|
+
whereas all other microservices have user privileges.
|
|
9
|
+
For example, it is usefull for a testing solution needing to restart a microservice of the SUT (System Under Test),
|
|
10
|
+
but the testing solution docker image has not the privileges to do it.
|
|
11
|
+
paths:
|
|
12
|
+
/os/env:
|
|
13
|
+
get:
|
|
14
|
+
description: "Get environment variable values"
|
|
15
|
+
requestBody:
|
|
16
|
+
content:
|
|
17
|
+
application/json:
|
|
18
|
+
schema:
|
|
19
|
+
type: "array"
|
|
20
|
+
items:
|
|
21
|
+
type: "string"
|
|
22
|
+
responses:
|
|
23
|
+
200:
|
|
24
|
+
description: "Environment variable values"
|
|
25
|
+
content:
|
|
26
|
+
application/json:
|
|
27
|
+
schema:
|
|
28
|
+
type: "array"
|
|
29
|
+
items:
|
|
30
|
+
type: "object"
|
|
31
|
+
|
|
32
|
+
/os/ls:
|
|
33
|
+
get:
|
|
34
|
+
description: "List directory filenames"
|
|
35
|
+
requestBody:
|
|
36
|
+
content:
|
|
37
|
+
application/json:
|
|
38
|
+
schema:
|
|
39
|
+
type: "object"
|
|
40
|
+
properties:
|
|
41
|
+
path:
|
|
42
|
+
type: string
|
|
43
|
+
extension:
|
|
44
|
+
type: string
|
|
45
|
+
nullable: true
|
|
46
|
+
responses:
|
|
47
|
+
200:
|
|
48
|
+
description: "Directory filenames"
|
|
49
|
+
content:
|
|
50
|
+
application/json:
|
|
51
|
+
schema:
|
|
52
|
+
type: "array"
|
|
53
|
+
items:
|
|
54
|
+
type: "string"
|
|
55
|
+
|
|
56
|
+
/docker/container:
|
|
57
|
+
get:
|
|
58
|
+
description: "List containers and their status"
|
|
59
|
+
parameters:
|
|
60
|
+
- in: "query"
|
|
61
|
+
name: "all"
|
|
62
|
+
description: "if set to 'true', list all containers, not only running ones"
|
|
63
|
+
schema:
|
|
64
|
+
type: "boolean"
|
|
65
|
+
default: false
|
|
66
|
+
responses:
|
|
67
|
+
200:
|
|
68
|
+
description: "List of container names with their status"
|
|
69
|
+
content:
|
|
70
|
+
application/json:
|
|
71
|
+
schema:
|
|
72
|
+
type: "array"
|
|
73
|
+
items:
|
|
74
|
+
type: "string"
|
|
75
|
+
/docker/container/{name}:
|
|
76
|
+
get:
|
|
77
|
+
description: "Display all information of a container"
|
|
78
|
+
parameters:
|
|
79
|
+
- in: "path"
|
|
80
|
+
name: "name"
|
|
81
|
+
description: "Container name"
|
|
82
|
+
required: true
|
|
83
|
+
schema:
|
|
84
|
+
type: "string"
|
|
85
|
+
- in: "query"
|
|
86
|
+
name: "all"
|
|
87
|
+
description: "if set to 'true', search container in all containers, not only running ones"
|
|
88
|
+
schema:
|
|
89
|
+
type: "boolean"
|
|
90
|
+
default: false
|
|
91
|
+
responses:
|
|
92
|
+
200:
|
|
93
|
+
description: "Container information"
|
|
94
|
+
content:
|
|
95
|
+
application/json:
|
|
96
|
+
schema:
|
|
97
|
+
type: "string"
|
|
98
|
+
/docker/container/{name}/restart:
|
|
99
|
+
put:
|
|
100
|
+
description: "Restart a container"
|
|
101
|
+
parameters:
|
|
102
|
+
- in: "path"
|
|
103
|
+
name: "name"
|
|
104
|
+
description: "Container name"
|
|
105
|
+
required: true
|
|
106
|
+
schema:
|
|
107
|
+
type: "string"
|
|
108
|
+
requestBody:
|
|
109
|
+
content:
|
|
110
|
+
application/json:
|
|
111
|
+
schema:
|
|
112
|
+
type: "object"
|
|
113
|
+
nullable: true
|
|
114
|
+
responses:
|
|
115
|
+
200:
|
|
116
|
+
description: ""
|
|
117
|
+
content:
|
|
118
|
+
application/json:
|
|
119
|
+
schema:
|
|
120
|
+
type: "string"
|
|
121
|
+
/docker/container/{name}/start:
|
|
122
|
+
put:
|
|
123
|
+
description: "Start a container"
|
|
124
|
+
parameters:
|
|
125
|
+
- in: "path"
|
|
126
|
+
name: "name"
|
|
127
|
+
description: "Container name"
|
|
128
|
+
required: true
|
|
129
|
+
schema:
|
|
130
|
+
type: "string"
|
|
131
|
+
requestBody:
|
|
132
|
+
content:
|
|
133
|
+
application/json:
|
|
134
|
+
schema:
|
|
135
|
+
type: "object"
|
|
136
|
+
nullable: true
|
|
137
|
+
responses:
|
|
138
|
+
200:
|
|
139
|
+
description: ""
|
|
140
|
+
content:
|
|
141
|
+
application/json:
|
|
142
|
+
schema:
|
|
143
|
+
type: "string"
|
|
144
|
+
/docker/container/{name}/stop:
|
|
145
|
+
put:
|
|
146
|
+
description: "Stop a container"
|
|
147
|
+
parameters:
|
|
148
|
+
- in: "path"
|
|
149
|
+
name: "name"
|
|
150
|
+
description: "Container name"
|
|
151
|
+
required: true
|
|
152
|
+
schema:
|
|
153
|
+
type: "string"
|
|
154
|
+
requestBody:
|
|
155
|
+
content:
|
|
156
|
+
application/json:
|
|
157
|
+
schema:
|
|
158
|
+
type: "object"
|
|
159
|
+
nullable: true
|
|
160
|
+
responses:
|
|
161
|
+
200:
|
|
162
|
+
description: ""
|
|
163
|
+
content:
|
|
164
|
+
application/json:
|
|
165
|
+
schema:
|
|
166
|
+
type: "string"
|
|
167
|
+
/docker/container/{name}/wait:
|
|
168
|
+
put:
|
|
169
|
+
description: "Wait until a container is stopped"
|
|
170
|
+
parameters:
|
|
171
|
+
- in: "path"
|
|
172
|
+
name: "name"
|
|
173
|
+
description: "Container name"
|
|
174
|
+
required: true
|
|
175
|
+
schema:
|
|
176
|
+
type: "string"
|
|
177
|
+
requestBody:
|
|
178
|
+
content:
|
|
179
|
+
application/json:
|
|
180
|
+
schema:
|
|
181
|
+
type: "object"
|
|
182
|
+
nullable: true
|
|
183
|
+
responses:
|
|
184
|
+
200:
|
|
185
|
+
description: ""
|
|
186
|
+
content:
|
|
187
|
+
application/json:
|
|
188
|
+
schema:
|
|
189
|
+
type: "string"
|
|
190
|
+
|
|
191
|
+
/config/yaml_file:
|
|
192
|
+
get:
|
|
193
|
+
description: "Get content of a YAML file"
|
|
194
|
+
requestBody:
|
|
195
|
+
content:
|
|
196
|
+
application/json:
|
|
197
|
+
schema:
|
|
198
|
+
type: "object"
|
|
199
|
+
properties:
|
|
200
|
+
file_path:
|
|
201
|
+
type: string
|
|
202
|
+
responses:
|
|
203
|
+
200:
|
|
204
|
+
description: ""
|
|
205
|
+
content:
|
|
206
|
+
application/text:
|
|
207
|
+
schema:
|
|
208
|
+
type: "string"
|
|
209
|
+
patch:
|
|
210
|
+
description: "Update a YAML file"
|
|
211
|
+
requestBody:
|
|
212
|
+
content:
|
|
213
|
+
application/json:
|
|
214
|
+
schema:
|
|
215
|
+
type: "object"
|
|
216
|
+
properties:
|
|
217
|
+
file_path:
|
|
218
|
+
type: string
|
|
219
|
+
yaml_string:
|
|
220
|
+
type: string
|
|
221
|
+
with_backup:
|
|
222
|
+
type: "boolean"
|
|
223
|
+
default: false
|
|
224
|
+
backup_extension:
|
|
225
|
+
type: string
|
|
226
|
+
default: '.bak'
|
|
227
|
+
responses:
|
|
228
|
+
200:
|
|
229
|
+
description: ""
|
|
230
|
+
content:
|
|
231
|
+
application/json:
|
|
232
|
+
schema:
|
|
233
|
+
type: "string"
|
|
234
|
+
put:
|
|
235
|
+
description: "Replace a YAML file"
|
|
236
|
+
requestBody:
|
|
237
|
+
content:
|
|
238
|
+
application/json:
|
|
239
|
+
schema:
|
|
240
|
+
type: "object"
|
|
241
|
+
properties:
|
|
242
|
+
action:
|
|
243
|
+
description: "Action to perform"
|
|
244
|
+
type: string
|
|
245
|
+
enum:
|
|
246
|
+
- "restore"
|
|
247
|
+
file_path:
|
|
248
|
+
type: string
|
|
249
|
+
backup_extension:
|
|
250
|
+
type: string
|
|
251
|
+
default: '.bak'
|
|
252
|
+
responses:
|
|
253
|
+
200:
|
|
254
|
+
description: ""
|
|
255
|
+
content:
|
|
256
|
+
application/json:
|
|
257
|
+
schema:
|
|
258
|
+
type: "string"
|
|
259
|
+
|
|
260
|
+
components:
|
|
261
|
+
securitySchemes: {}
|
|
262
|
+
schemas:
|
|
263
|
+
DockerControler:
|
|
264
|
+
properties: {}
|
|
265
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
|
22
|
+
initialize(TSessionContext=None, use_holado_logger=True, logging_config_file_path=None,
|
|
23
|
+
log_level=None, log_time_in_utc=None, log_on_console=True, log_in_file=False,
|
|
24
|
+
config_kwargs={'application_group':'host_controller'},
|
|
25
|
+
garbage_collector_periodicity=None)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
app = connexion.FlaskApp(__name__, pythonic_params=True)
|
|
29
|
+
app.add_api('openapi.yaml',
|
|
30
|
+
resolver=MethodViewResolver('api'), resolver_error=501,
|
|
31
|
+
pythonic_params=True)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Script to launch Host Controller as a docker image.
|
|
4
|
+
#
|
|
5
|
+
# Host Controller exposes a REST API with host services.
|
|
6
|
+
# It is accessible on localhost, and also on a docker network if HOLADO_NETWORK is defined.
|
|
7
|
+
# API is accessible on port HOLADO_HOST_CONTROLLER_HOSTPORT from localhost and port HOLADO_HOST_CONTROLLER_PORT from network.
|
|
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_HOST_CONTROLLER_HOST: host name or name of the container
|
|
16
|
+
# - HOLADO_HOST_CONTROLLER_HOSTPORT: REST API port to use from localhost (default: 51231)
|
|
17
|
+
# - HOLADO_HOST_CONTROLLER_PORT: REST API port to use from network HOLADO_NETWORK (default: 51231)
|
|
18
|
+
# - HOLADO_IMAGE_REGISTRY: docker image registry to use (default: holado/host_controller)
|
|
19
|
+
# - HOLADO_IMAGE_TAG: docker image tag to use (default: latest)
|
|
20
|
+
# - HOLADO_OUTPUT_BASEDIR: absolute path to base output directory (default: [HOME]/.holado/output)
|
|
21
|
+
# - HOLADO_USE_LOCALHOST: force the container network to 'host'.
|
|
22
|
+
# - HOLADO_NETWORK: specify on which network the docker is run.
|
|
23
|
+
#
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
WORK_DIR="$(pwd)"
|
|
27
|
+
|
|
28
|
+
if [[ -z "$HOLADO_IMAGE_REGISTRY" ]]; then
|
|
29
|
+
HOLADO_IMAGE_REGISTRY=holado/host_controller
|
|
30
|
+
fi
|
|
31
|
+
if [[ -z "$HOLADO_IMAGE_TAG" ]]; then
|
|
32
|
+
HOLADO_IMAGE_TAG=latest
|
|
33
|
+
fi
|
|
34
|
+
CONTROLLER_IMAGE=${HOLADO_IMAGE_REGISTRY}:${HOLADO_IMAGE_TAG}
|
|
35
|
+
|
|
36
|
+
# Update docker image
|
|
37
|
+
echo "Updating docker image ${CONTROLLER_IMAGE}..."
|
|
38
|
+
docker pull ${CONTROLLER_IMAGE}
|
|
39
|
+
|
|
40
|
+
# Define test output directory
|
|
41
|
+
if [[ ! -z "$HOLADO_OUTPUT_BASEDIR" ]]; then
|
|
42
|
+
OUTPUT_DIR=${HOLADO_OUTPUT_BASEDIR}
|
|
43
|
+
else
|
|
44
|
+
OUTPUT_DIR=${HOME}/.holado/output
|
|
45
|
+
fi
|
|
46
|
+
echo "Output directory: $OUTPUT_DIR"
|
|
47
|
+
|
|
48
|
+
# Define test resources directory
|
|
49
|
+
if [[ ! -z "$HOLADO_LOCAL_RESOURCES_BASEDIR" ]]; then
|
|
50
|
+
RESOURCES_DIR=${HOLADO_LOCAL_RESOURCES_BASEDIR}
|
|
51
|
+
else
|
|
52
|
+
RESOURCES_DIR=${HOME}/.holado/resources
|
|
53
|
+
fi
|
|
54
|
+
echo "Resources directory: $RESOURCES_DIR"
|
|
55
|
+
|
|
56
|
+
# Make dirs
|
|
57
|
+
if [ ! -d ${OUTPUT_DIR} ]; then
|
|
58
|
+
echo "Create output directory: ${OUTPUT_DIR}"
|
|
59
|
+
mkdir -p ${OUTPUT_DIR}
|
|
60
|
+
fi
|
|
61
|
+
if [ ! -d ${RESOURCES_DIR} ]; then
|
|
62
|
+
echo "Create resources directory: ${RESOURCES_DIR}"
|
|
63
|
+
mkdir -p ${RESOURCES_DIR}
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
# Define container network
|
|
67
|
+
if [ "$HOLADO_USE_LOCALHOST" = True ]; then
|
|
68
|
+
NETWORK_DEF_COMMAND="--network=host"
|
|
69
|
+
else
|
|
70
|
+
if [[ ! -z "$HOLADO_NETWORK" ]]; then
|
|
71
|
+
NETWORK_DEF_COMMAND="--network $HOLADO_NETWORK"
|
|
72
|
+
else
|
|
73
|
+
NETWORK_DEF_COMMAND=""
|
|
74
|
+
fi
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
# Define ports to use
|
|
78
|
+
if [[ -z "$HOLADO_HOST_CONTROLLER_HOSTPORT" ]]; then
|
|
79
|
+
HOLADO_HOST_CONTROLLER_HOSTPORT=51231
|
|
80
|
+
fi
|
|
81
|
+
if [[ -z "$HOLADO_HOST_CONTROLLER_PORT" ]]; then
|
|
82
|
+
HOLADO_HOST_CONTROLLER_PORT=51231
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
# Docker run
|
|
86
|
+
if [[ -z "$HOLADO_HOST_CONTROLLER_HOST" ]]; then
|
|
87
|
+
HOLADO_HOST_CONTROLLER_HOST=holado_host_controller
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
echo
|
|
91
|
+
echo "Running Host Controller..."
|
|
92
|
+
echo " container name: ${HOLADO_HOST_CONTROLLER_HOST}"
|
|
93
|
+
echo " host port: ${HOLADO_HOST_CONTROLLER_HOSTPORT}"
|
|
94
|
+
echo " port: ${HOLADO_HOST_CONTROLLER_PORT}"
|
|
95
|
+
#echo " NETWORK_DEF_COMMAND=${NETWORK_DEF_COMMAND}"
|
|
96
|
+
echo
|
|
97
|
+
docker run --rm --user root --name ${HOLADO_HOST_CONTROLLER_HOST} \
|
|
98
|
+
--privileged -v $(docker info --format '{{.SecurityOptions}}' | grep -q rootless && echo -n "/run/user/$(id -u ${USER})/docker.sock" || echo -n "/var/run/docker.sock"):/var/run/docker.sock \
|
|
99
|
+
-v "${OUTPUT_DIR}":/output \
|
|
100
|
+
-v "${RESOURCES_DIR}":/resources \
|
|
101
|
+
-e HOLADO_OUTPUT_BASEDIR=/output \
|
|
102
|
+
-e HOLADO_LOCAL_RESOURCES_BASEDIR=/resources \
|
|
103
|
+
-e HOLADO_HOST_CONTROLLER_PORT=${HOLADO_HOST_CONTROLLER_PORT} \
|
|
104
|
+
${NETWORK_DEF_COMMAND} \
|
|
105
|
+
-p ${HOLADO_HOST_CONTROLLER_HOSTPORT}:${HOLADO_HOST_CONTROLLER_PORT} \
|
|
106
|
+
${CONTROLLER_IMAGE}
|
|
107
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
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 undefined_argument, undefined_value
|
|
17
|
+
import os
|
|
18
|
+
from holado_core.common.tools.converters.converter import Converter
|
|
19
|
+
from holado_rest.api.rest.rest_manager import RestManager
|
|
20
|
+
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class HostViewerClient(RestClient):
|
|
25
|
+
|
|
26
|
+
@classmethod
|
|
27
|
+
def new_client(cls, use_localhost=undefined_argument, **kwargs):
|
|
28
|
+
if 'name' not in kwargs:
|
|
29
|
+
kwargs['name'] = None
|
|
30
|
+
if 'url' not in kwargs:
|
|
31
|
+
if use_localhost is undefined_argument:
|
|
32
|
+
env_use = os.getenv("HOLADO_USE_LOCALHOST", False)
|
|
33
|
+
use_localhost = Converter.is_boolean(env_use) and Converter.to_boolean(env_use)
|
|
34
|
+
|
|
35
|
+
url = os.getenv("HOLADO_HOST_VIEWER_URL", undefined_value)
|
|
36
|
+
if url is undefined_value:
|
|
37
|
+
scheme = kwargs.get('scheme', undefined_value)
|
|
38
|
+
if scheme is undefined_value:
|
|
39
|
+
scheme = os.getenv("HOLADO_HOST_VIEWER_SCHEME", "http")
|
|
40
|
+
host = kwargs.get('host', undefined_value)
|
|
41
|
+
if host is undefined_value:
|
|
42
|
+
host = "localhost" if use_localhost else os.getenv("HOLADO_HOST_VIEWER_HOST", "holado_docker_viewer")
|
|
43
|
+
port = kwargs.get('port', undefined_value)
|
|
44
|
+
if port is undefined_value:
|
|
45
|
+
if use_localhost:
|
|
46
|
+
port = os.getenv("HOLADO_HOST_VIEWER_HOSTPORT", 51231)
|
|
47
|
+
else:
|
|
48
|
+
port = os.getenv("HOLADO_HOST_VIEWER_PORT", 51231)
|
|
49
|
+
|
|
50
|
+
if port is None:
|
|
51
|
+
url = f"{scheme}://{host}"
|
|
52
|
+
else:
|
|
53
|
+
url = f"{scheme}://{host}:{port}"
|
|
54
|
+
kwargs['url'] = url
|
|
55
|
+
|
|
56
|
+
manager = RestManager(default_client_class=HostViewerClient)
|
|
57
|
+
res = manager.new_client(**kwargs)
|
|
58
|
+
|
|
59
|
+
return res
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def __init__(self, name, url, headers=None):
|
|
63
|
+
super().__init__(name, url, headers)
|
|
64
|
+
|
|
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
|
+
if all_:
|
|
90
|
+
response = self.get(f"docker/container/{name}?all=true")
|
|
91
|
+
else:
|
|
92
|
+
response = self.get(f"docker/container/{name}")
|
|
93
|
+
return self.response_result(response, status_ok=[200,204])
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
@@ -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_viewer/requirements.txt
|
|
26
|
+
WORKDIR /code/host_viewer
|
|
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 viewer sources
|
|
53
|
+
COPY --chown=appuser ./rest /code/host_viewer
|
|
54
|
+
|
|
55
|
+
# Activate permanently python venv
|
|
56
|
+
ENV PATH=/code/env/bin:$PATH
|
|
57
|
+
|
|
58
|
+
WORKDIR /code/host_viewer
|
|
59
|
+
CMD ["sh", "-c", "uvicorn run:app --host 0.0.0.0 --port $HOLADO_HOST_VIEWER_PORT"]
|
|
60
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
# def _get_session_context():
|
|
21
|
+
# return SessionContext.instance()
|
|
22
|
+
|
|
@@ -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
|