mirror of
https://gitlab.sectorq.eu/jaydee/portainer.git
synced 2026-05-04 14:49:49 +02:00
build
This commit is contained in:
@@ -140,7 +140,7 @@ parser.add_argument(
|
||||
default=None,
|
||||
help="Service ID to limit service operations",
|
||||
)
|
||||
parser.add_argument("--stack", "-s", type=str, default=None, nargs="+", help="Stack ID for operations")
|
||||
parser.add_argument("--stack", "-s", type=str, default=None, help="Stack ID for operations")
|
||||
parser.add_argument("--action", "-a", type=str, default=None, help="Action to perform")
|
||||
parser.add_argument(
|
||||
"--autostart", "-Z", action="store_true", help="Auto-start created stacks"
|
||||
@@ -152,6 +152,8 @@ parser.add_argument("--gpu", "-g", action="store_true")
|
||||
parser.add_argument("--timeout", type=int, default=10, help="Request timeout seconds")
|
||||
parser.add_argument("--deploy-mode", "-m", type=str, default="git", help="Deploy mode")
|
||||
parser.add_argument("--stack-mode", "-w", default=None, help="Stack mode")
|
||||
parser.add_argument("--print-command", "-P", action="store_true", help="Print quick command from action")
|
||||
|
||||
parser.add_argument(
|
||||
"-E", "--excluded",
|
||||
nargs="+",
|
||||
@@ -322,7 +324,7 @@ def prompt_missing_args(args_in, defaults_in, fields, action=None,stacks=None):
|
||||
value_in.sort()
|
||||
|
||||
if "pihole" in value_in:
|
||||
if args.action == "delete_stack":
|
||||
if args.action in ["delete_stack","stop_stack"]:
|
||||
value_in.remove("pihole")
|
||||
value_in.append("pihole")
|
||||
else:
|
||||
@@ -469,7 +471,6 @@ if __name__ == "__main__":
|
||||
for key, value in secrets.items():
|
||||
res = por.create_secret(key, value, args.endpoint_id, args.timeout)
|
||||
print(res)
|
||||
sys.exit()
|
||||
|
||||
if args.action == "delete_stack":
|
||||
args = prompt_missing_args(
|
||||
@@ -490,7 +491,6 @@ if __name__ == "__main__":
|
||||
args.endpoint_id,
|
||||
args.stack,
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
if args.action == "create_stack":
|
||||
por.action = "create_stack"
|
||||
@@ -515,7 +515,7 @@ if __name__ == "__main__":
|
||||
args.autostart,
|
||||
args.stack_mode,
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "stop_stack":
|
||||
args = prompt_missing_args(
|
||||
@@ -529,7 +529,6 @@ if __name__ == "__main__":
|
||||
)
|
||||
|
||||
por.stop_stack(args.stack, args.endpoint_id)
|
||||
sys.exit()
|
||||
|
||||
if args.action == "start_stack":
|
||||
args = prompt_missing_args(
|
||||
@@ -542,7 +541,7 @@ if __name__ == "__main__":
|
||||
],
|
||||
)
|
||||
por.start_stack(args.stack, args.endpoint_id)
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "restart_service":
|
||||
args = prompt_missing_args(
|
||||
@@ -554,7 +553,7 @@ if __name__ == "__main__":
|
||||
],
|
||||
)
|
||||
por.restart_service(args.endpoint_id, "lala")
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "update_service":
|
||||
args = prompt_missing_args(
|
||||
@@ -568,7 +567,7 @@ if __name__ == "__main__":
|
||||
por.update_service()
|
||||
if args.launcher:
|
||||
input("\nPress ENTER to continue...")
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "update_containers":
|
||||
|
||||
@@ -583,7 +582,6 @@ if __name__ == "__main__":
|
||||
],
|
||||
)
|
||||
por.update_containers()
|
||||
sys.exit()
|
||||
|
||||
if args.action == "list_stacks":
|
||||
args = prompt_missing_args(
|
||||
@@ -598,21 +596,19 @@ if __name__ == "__main__":
|
||||
if args.launcher:
|
||||
input("Press ENTER to continue...")
|
||||
# print(json.dumps(por.all_data, indent=2))
|
||||
sys.exit()
|
||||
|
||||
if args.action == "list_all_stacks":
|
||||
por.get_stacks_failed()
|
||||
if args.launcher:
|
||||
input("Press ENTER to continue...")
|
||||
# print(json.dumps(por.all_data, indent=2))
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "delete_ophaned_stacks":
|
||||
por.delete_failed_stack()
|
||||
if args.launcher:
|
||||
input("Press ENTER to continue...")
|
||||
# print(json.dumps(por.all_data, indent=2))
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "list_containers":
|
||||
@@ -628,7 +624,6 @@ if __name__ == "__main__":
|
||||
print("\n".join(por.get_containers()))
|
||||
if args.launcher:
|
||||
input("\nPress ENTER to continue...")
|
||||
sys.exit()
|
||||
|
||||
if args.action == "update_stack":
|
||||
args = prompt_missing_args(
|
||||
@@ -643,17 +638,16 @@ if __name__ == "__main__":
|
||||
por.update_stack(args)
|
||||
if args.launcher:
|
||||
input("\nPress ENTER to continue...")
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "print_all_data":
|
||||
print(json.dumps(por.all_data, indent=2))
|
||||
if args.launcher:
|
||||
input("\nPress ENTER to continue...")
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "update_status":
|
||||
por.update_status(args.endpoint_id, args.stack)
|
||||
sys.exit()
|
||||
|
||||
if args.action == "list_endpoints":
|
||||
eps = por.get_endpoints(args)
|
||||
@@ -664,7 +658,7 @@ if __name__ == "__main__":
|
||||
print(tabulate(export_data, headers=headers, tablefmt="github"))
|
||||
if args.launcher:
|
||||
input("\nPress ENTER to continue...")
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "stop_containers":
|
||||
# TODO: does not work
|
||||
@@ -678,14 +672,14 @@ if __name__ == "__main__":
|
||||
)
|
||||
if por.all_data["endpoints_status"][args.endpoint_id] != 1:
|
||||
print(f"Endpoint {por.get_endpoint_name(args.endpoint_id)} is offline")
|
||||
sys.exit()
|
||||
|
||||
print(f"Stopping containers on {por.get_endpoint_name(args.endpoint_id)}")
|
||||
cont = []
|
||||
for c in por.all_data["containers"][args.endpoint_id]:
|
||||
if args.stack in (c, "all"):
|
||||
cont += por.all_data["containers"][args.endpoint_id][c]
|
||||
por.stop_containers(args.endpoint_id, cont)
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "start_containers":
|
||||
print("Starting containers")
|
||||
@@ -695,7 +689,7 @@ if __name__ == "__main__":
|
||||
if args.stack in (c, "all"):
|
||||
cont += por.all_data["containers"][args.endpoint_id][c]
|
||||
por.start_containers(args.endpoint_id, cont)
|
||||
sys.exit()
|
||||
|
||||
if args.action == "start_containers":
|
||||
print("Starting containers")
|
||||
cont = []
|
||||
@@ -704,10 +698,27 @@ if __name__ == "__main__":
|
||||
if args.stack in (c, "all"):
|
||||
cont += por.all_data["containers"][args.endpoint_id][c]
|
||||
por.start_containers(args.endpoint_id, cont)
|
||||
sys.exit()
|
||||
|
||||
if args.action == "refresh_environment":
|
||||
cont = por.refresh()
|
||||
sys.exit()
|
||||
|
||||
|
||||
if args.action == "refresh_status":
|
||||
por.refresh_status(args)
|
||||
|
||||
if args.print_command:
|
||||
one_time_command = "portainer"
|
||||
if args.action:
|
||||
one_time_command += f" --action={args.action}"
|
||||
if por.endpoint_name:
|
||||
one_time_command += f" --endpoint-id={por.endpoint_name}"
|
||||
if por.site:
|
||||
one_time_command += f" --site={por.site}"
|
||||
if args.stack:
|
||||
if type(args.stack) == list:
|
||||
args.stack = ",".join(args.stack)
|
||||
one_time_command += f" --stack={args.stack}"
|
||||
width = shutil.get_terminal_size().columns
|
||||
print("#"*width)
|
||||
print(f"COMMAND : {one_time_command}")
|
||||
print("#"*width)
|
||||
Binary file not shown.
+7
-1
@@ -37,6 +37,7 @@ class PortainerApi:
|
||||
self.timeout = timeout
|
||||
self.git_url = "git@gitlab.sectorq.eu:home/docker-compose.git"
|
||||
self.stack_name = None
|
||||
self.stack_names = []
|
||||
self.stacks_all = {}
|
||||
self.stack_id = None
|
||||
self.stack_ids = []
|
||||
@@ -122,6 +123,7 @@ class PortainerApi:
|
||||
self.cur_config = config
|
||||
|
||||
def get_site(self, site):
|
||||
self.site = site
|
||||
if site == "portainer":
|
||||
self.base_url = os.getenv(
|
||||
"PORTAINER_URL", "https://portainer.sectorq.eu/api"
|
||||
@@ -1221,6 +1223,8 @@ class PortainerApi:
|
||||
self.get_endpoint(endpoint_id)
|
||||
size = 0
|
||||
if stack is not None:
|
||||
if type(stack) == str:
|
||||
stack = stack.split(",")
|
||||
for s in stack:
|
||||
if len(s) > size:
|
||||
size = len(s)
|
||||
@@ -1261,6 +1265,8 @@ class PortainerApi:
|
||||
self.get_endpoint(endpoint_id)
|
||||
size = 0
|
||||
if stack is not None:
|
||||
if type(stack) == str:
|
||||
stack = stack.split(",")
|
||||
for s in stack:
|
||||
if size < len(s):
|
||||
size = len(s)
|
||||
@@ -1269,7 +1275,7 @@ class PortainerApi:
|
||||
self.stack_ids = list(dict.fromkeys(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)}",
|
||||
f"Stopping stack {self.stacks_all[self.endpoint_id]['by_id'][stck]}",
|
||||
end="",
|
||||
flush=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user