This commit is contained in:
2026-03-21 10:36:53 +01:00
parent 9986c1bc03
commit 4a3609ef27
2 changed files with 43 additions and 13 deletions
+5 -2
View File
@@ -302,6 +302,7 @@ def prompt_missing_args(args_in, defaults_in, fields, action=None,stacks=None):
commands.sort() commands.sort()
commands_tuples = [(cmd, cmd) for cmd in commands] commands_tuples = [(cmd, cmd) for cmd in commands]
commands_tuples.insert(0, ("__ALL__", "[Select ALL]")) commands_tuples.insert(0, ("__ALL__", "[Select ALL]"))
commands_tuples.insert(0, ("mandatory", "[Mandatory]"))
value_in = checkboxlist_dialog( value_in = checkboxlist_dialog(
title="Select Services", title="Select Services",
text="Choose one or more services:", text="Choose one or more services:",
@@ -314,12 +315,14 @@ def prompt_missing_args(args_in, defaults_in, fields, action=None,stacks=None):
elif "__ALL__" in value_in: elif "__ALL__" in value_in:
# User selected "Select ALL" # User selected "Select ALL"
value_in = commands # all real commands value_in = commands # all real commands
elif "mandatory" in value_in:
# User selected "Select ALL"
value_in = ['pihole', 'nginx', 'authentik', 'hashicorp', 'mosquitto','homepage', 'mailu3', 'home-assistant', 'mediacenter' ] # all real commands
value_in.sort() value_in.sort()
if "pihole" in value_in: if "pihole" in value_in:
if action == "delete_stack": if args.action == "delete_stack":
value_in.remove("pihole") value_in.remove("pihole")
value_in.append("pihole") value_in.append("pihole")
else: else:
+38 -11
View File
@@ -657,6 +657,11 @@ class PortainerApi:
stack_mode="swarm", stack_mode="swarm",
): ):
for stack in stacks: for stack in stacks:
if self.endpoint_name == "nas":
server = "_nas"
else:
server = ""
if stack_mode == "swarm": if stack_mode == "swarm":
swarm_id = self.get_swarm_id(endpoint) swarm_id = self.get_swarm_id(endpoint)
p = "swarm" p = "swarm"
@@ -748,8 +753,8 @@ class PortainerApi:
}, },
"repositoryURL": "https://gitlab.sectorq.eu/home/docker-compose.git", "repositoryURL": "https://gitlab.sectorq.eu/home/docker-compose.git",
"ReferenceName": "refs/heads/main", "ReferenceName": "refs/heads/main",
"composeFile": f"{stack}/docker-compose.yml", "composeFile": f"{stack}/docker-compose{server}.yml",
"ConfigFilePath": f"{stack}/docker-compose.yml", "ConfigFilePath": f"{stack}/docker-compose{server}.yml",
"repositoryAuthentication": True, "repositoryAuthentication": True,
"repositoryUsername": "jaydee", "repositoryUsername": "jaydee",
"repositoryPassword": "glpat-uj-n-eEfTY398PE4vKSS", "repositoryPassword": "glpat-uj-n-eEfTY398PE4vKSS",
@@ -1208,25 +1213,36 @@ class PortainerApi:
def start_stack(self, stack=None, endpoint_id=None): def start_stack(self, stack=None, endpoint_id=None):
"""Start one stack or all stacks on an endpoint.""" """Start one stack or all stacks on an endpoint."""
ok = "\033[92m✔\033[0m"
ok2 = "\033[93m✔\033[0m"
err = "\033[91m✖\033[0m"
if endpoint_id is not None: if endpoint_id is not None:
print("Getting endpoint") print("Getting endpoint")
self.get_endpoint(endpoint_id) self.get_endpoint(endpoint_id)
size = 0
if stack is not None: if stack is not None:
for s in stack: for s in stack:
if len(s) > size:
size = len(s)
self.stack_ids.append(self._resolve_stack_id(s, endpoint_id)) self.stack_ids.append(self._resolve_stack_id(s, endpoint_id))
size = size + 5
for stck in self.stack_ids: for stck in self.stack_ids:
print(
f"Starting stack {self.stacks_all[self.endpoint_id]['by_id'][stck][:size].ljust(size)}",
end="", flush=True
)
path = f"/stacks/{stck}/start" path = f"/stacks/{stck}/start"
if self.endpoint_id is not None: if self.endpoint_id is not None:
path += f"?endpointId={self.endpoint_id}" path += f"?endpointId={self.endpoint_id}"
try: try:
resp = self._api_post_no_body(path, timeout=20) resp = self._api_post_no_body(path, timeout=120)
except ValueError as e: except ValueError as e:
print(f"Error stoping stack: {e}") print(f"Error starting stack: {e}")
return [] return []
if "Id" in json.loads(resp): if "Id" in json.loads(resp):
print( print(ok)
f"Stack {self.stacks_all[self.endpoint_id]['by_id'][stck]} : started" elif "already running" in json.loads(resp)['message']:
) print(ok2)
else: else:
print( print(
f"Stack {self.stacks_all[self.endpoint_id]['by_id'][stck]} : {json.loads(resp)['message']}" f"Stack {self.stacks_all[self.endpoint_id]['by_id'][stck]} : {json.loads(resp)['message']}"
@@ -1238,14 +1254,25 @@ class PortainerApi:
"""Stop one stack or all stacks on an endpoint.""" """Stop one stack or all stacks on an endpoint."""
# print(f"Stopping stack {stack}") # print(f"Stopping stack {stack}")
ok = "\033[92m✔\033[0m"
ok2 = "\033[93m✔\033[0m"
err = "\033[91m✖\033[0m"
if endpoint_id is not None: if endpoint_id is not None:
self.get_endpoint(endpoint_id) self.get_endpoint(endpoint_id)
size = 0
if stack is not None: if stack is not None:
for s in stack: for s in stack:
if size < len(s):
size = len(s)
self.stack_ids.append(self._resolve_stack_id(s, endpoint_id)) self.stack_ids.append(self._resolve_stack_id(s, endpoint_id))
size = size + 5
self.stack_ids = list(dict.fromkeys(self.stack_ids)) self.stack_ids = list(dict.fromkeys(self.stack_ids))
for stck in self.stack_ids: for stck in self.stack_ids:
print(
f"Stopping stack {self.stacks_all[self.endpoint_id]['by_id'][stck][:size].ljust(size)}",
end="",
flush=True
)
path = f"/stacks/{stck}/stop" path = f"/stacks/{stck}/stop"
# print(path) # print(path)
if self.endpoint_id is not None: if self.endpoint_id is not None:
@@ -1256,9 +1283,9 @@ class PortainerApi:
print(f"Error stopping stack: {e}") print(f"Error stopping stack: {e}")
return [] return []
if "Id" in json.loads(resp): if "Id" in json.loads(resp):
print( print(ok)
f"Stack {self.stacks_all[self.endpoint_id]['by_id'][stck]} : stopped" elif "already inactive" in json.loads(resp)['message']:
) print(ok2)
else: else:
print( print(
f"Stack {self.stacks_all[self.endpoint_id]['by_id'][stck]} : {json.loads(resp)['message']}" f"Stack {self.stacks_all[self.endpoint_id]['by_id'][stck]} : {json.loads(resp)['message']}"