mirror of
https://gitlab.sectorq.eu/jaydee/portainer.git
synced 2025-12-14 18:44:53 +01:00
build
This commit is contained in:
30
port.py
30
port.py
@@ -472,18 +472,22 @@ class Portainer:
|
|||||||
self.stack_name = s.get("Name")
|
self.stack_name = s.get("Name")
|
||||||
self.stack_ids.append(s.get("Id"))
|
self.stack_ids.append(s.get("Id"))
|
||||||
return s
|
return s
|
||||||
|
RED = "\033[91m"
|
||||||
print(ValueError(f"Stack not found: {stack}"))
|
RESET = "\033[0m"
|
||||||
sys.exit(1)
|
print(ValueError(f"{RED}✗{RESET} >> Stack not found: {stack}"))
|
||||||
|
return 1
|
||||||
|
|
||||||
def create_stack(
|
def create_stack(
|
||||||
self,
|
self,
|
||||||
endpoint,
|
endpoint,
|
||||||
stack=None,
|
stacks=None,
|
||||||
mode="git",
|
mode="git",
|
||||||
autostart=False,
|
autostart=False,
|
||||||
stack_mode="swarm",
|
stack_mode="swarm",
|
||||||
):
|
):
|
||||||
|
|
||||||
|
|
||||||
|
for stack in stacks:
|
||||||
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"
|
||||||
@@ -500,7 +504,7 @@ class Portainer:
|
|||||||
Repo.clone_from(self.git_url, self.repo_dir)
|
Repo.clone_from(self.git_url, self.repo_dir)
|
||||||
if mode == "git":
|
if mode == "git":
|
||||||
path = f"/stacks/create/{p}/repository"
|
path = f"/stacks/create/{p}/repository"
|
||||||
print(p)
|
# print(p)
|
||||||
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}"
|
||||||
|
|
||||||
@@ -526,7 +530,9 @@ class Portainer:
|
|||||||
or stack in self.stacks_all[self.endpoint_id]["by_name"]
|
or stack in self.stacks_all[self.endpoint_id]["by_name"]
|
||||||
)
|
)
|
||||||
if stack_check:
|
if stack_check:
|
||||||
print(f"Stack {stack} already exist")
|
GREEN = "\033[92m"
|
||||||
|
RESET = "\033[0m"
|
||||||
|
print(f"{GREEN}✓{RESET} >> Stack {stack} already exist")
|
||||||
continue
|
continue
|
||||||
print(f"Working on {stack} , stack mode: {stack_mode}")
|
print(f"Working on {stack} , stack mode: {stack_mode}")
|
||||||
|
|
||||||
@@ -613,7 +619,7 @@ class Portainer:
|
|||||||
try:
|
try:
|
||||||
# print(self.endpoint_id)
|
# print(self.endpoint_id)
|
||||||
# print(stack)
|
# print(stack)
|
||||||
self.get_stack(stack, self.endpoint_id)
|
if self.get_stack(stack, self.endpoint_id) != 1:
|
||||||
created = True
|
created = True
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -852,12 +858,16 @@ class Portainer:
|
|||||||
self._resolve_endpoint(endpoint_id)
|
self._resolve_endpoint(endpoint_id)
|
||||||
endpoint_id = self.endpoint_id
|
endpoint_id = self.endpoint_id
|
||||||
|
|
||||||
stack_id = self._resolve_stack_id(stack, endpoint_id)
|
|
||||||
|
|
||||||
|
|
||||||
if stack == "all":
|
if stack == "all":
|
||||||
return self._delete_all_stacks(endpoint_id)
|
return self._delete_all_stacks(endpoint_id)
|
||||||
|
else:
|
||||||
return self._delete_single_stack(stack_id, endpoint_id)
|
for s in stack:
|
||||||
|
stack_id = self._resolve_stack_id(s, endpoint_id)
|
||||||
|
self._delete_single_stack(stack_id, endpoint_id)
|
||||||
|
return "Done"
|
||||||
|
|
||||||
# def delete_stack(self, endpoint_id=None, stack=None):
|
# def delete_stack(self, endpoint_id=None, stack=None):
|
||||||
# """
|
# """
|
||||||
|
|||||||
27
portainer.py
27
portainer.py
@@ -141,7 +141,7 @@ parser.add_argument("--gpu", "-g", action="store_true")
|
|||||||
parser.add_argument("--create-stacks", "-C", action="store_true")
|
parser.add_argument("--create-stacks", "-C", action="store_true")
|
||||||
parser.add_argument("--refresh-status", "-r", action="store_true")
|
parser.add_argument("--refresh-status", "-r", action="store_true")
|
||||||
|
|
||||||
parser.add_argument("--stack", "-s", type=str, help="Stack ID for operations")
|
parser.add_argument("--stack", "-s", type=str, nargs="+", help="Stack ID for operations")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--token-only", action="store_true", help="Print auth token and exit"
|
"--token-only", action="store_true", help="Print auth token and exit"
|
||||||
)
|
)
|
||||||
@@ -152,7 +152,6 @@ args = parser.parse_args()
|
|||||||
print("Running version:", VERSION)
|
print("Running version:", VERSION)
|
||||||
print("Environment:", args.site)
|
print("Environment:", args.site)
|
||||||
|
|
||||||
|
|
||||||
if args.site is not None:
|
if args.site is not None:
|
||||||
cur_config["PORTAINER_SITE"] = args.site
|
cur_config["PORTAINER_SITE"] = args.site
|
||||||
if args.endpoint_id is not None:
|
if args.endpoint_id is not None:
|
||||||
@@ -272,12 +271,13 @@ def prompt_missing_args(args_in, defaults_in, fields):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
if field == "stack":
|
if field == "stack":
|
||||||
result = checkboxlist_dialog(
|
commands_tuples = [(cmd, cmd) for cmd in commands]
|
||||||
|
value_in = checkboxlist_dialog(
|
||||||
title="Select Services",
|
title="Select Services",
|
||||||
text="Choose one or more services:",
|
text="Choose one or more services:",
|
||||||
values=commands,
|
values=commands_tuples,
|
||||||
).run()
|
).run()
|
||||||
input(result)
|
print(" >> Stacks :", ",".join(value_in))
|
||||||
else:
|
else:
|
||||||
value_in = (
|
value_in = (
|
||||||
prompt(
|
prompt(
|
||||||
@@ -316,9 +316,14 @@ def prompt_missing_args(args_in, defaults_in, fields):
|
|||||||
print("Value entered:", value_in)
|
print("Value entered:", value_in)
|
||||||
defaults_in[f"PORTAINER_{field}".upper()] = value_in
|
defaults_in[f"PORTAINER_{field}".upper()] = value_in
|
||||||
setattr(args, field, value_in)
|
setattr(args, field, value_in)
|
||||||
os.environ[field] = value_in
|
|
||||||
if field == "site" and value_in != cur_site:
|
if field == "site" and value_in != cur_site:
|
||||||
por.get_site(value_in)
|
por.get_site(value_in)
|
||||||
|
|
||||||
|
if field == "stack" and value_in != cur_site:
|
||||||
|
os.environ[field] = ",".join(value_in)
|
||||||
|
else:
|
||||||
|
os.environ[field] = value_in
|
||||||
if por._debug:
|
if por._debug:
|
||||||
print(f"{defaults_in} {field} {value_in}")
|
print(f"{defaults_in} {field} {value_in}")
|
||||||
if field == "endpoint_id" and value_in != defaults_in.get(
|
if field == "endpoint_id" and value_in != defaults_in.get(
|
||||||
@@ -375,8 +380,14 @@ if __name__ == "__main__":
|
|||||||
if args.debug:
|
if args.debug:
|
||||||
por._debug = True
|
por._debug = True
|
||||||
if args.action == "secrets":
|
if args.action == "secrets":
|
||||||
if args.endpoint_id is None:
|
args = prompt_missing_args(
|
||||||
args.endpoint_id = input("Endpoint ID is required for creating secrets : ")
|
args,
|
||||||
|
cur_config,
|
||||||
|
[
|
||||||
|
("site", "Site"),
|
||||||
|
("endpoint_id", "Endpoint ID"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
secrets = {
|
secrets = {
|
||||||
"gitea_runner_registration_token": "8nmKqJhkvYwltmNfF2o9vs0tzo70ufHSQpVg6ymb",
|
"gitea_runner_registration_token": "8nmKqJhkvYwltmNfF2o9vs0tzo70ufHSQpVg6ymb",
|
||||||
|
|||||||
Reference in New Issue
Block a user