mirror of
https://gitlab.sectorq.eu/jaydee/portainer.git
synced 2025-12-14 10:44:52 +01:00
build
This commit is contained in:
38
portainer.py
38
portainer.py
@@ -107,7 +107,7 @@ if __name__ == "__main__":
|
|||||||
# Example usage: set PORTAINER_USER and PORTAINER_PASS in env, or pass literals below.
|
# Example usage: set PORTAINER_USER and PORTAINER_PASS in env, or pass literals below.
|
||||||
#token = get_portainer_token(base,"admin","l4c1j4yd33Du5lo") # or get_portainer_token(base, "admin", "secret")
|
#token = get_portainer_token(base,"admin","l4c1j4yd33Du5lo") # or get_portainer_token(base, "admin", "secret")
|
||||||
if args.action == None:
|
if args.action == None:
|
||||||
actions = ["delete_stack","create_stack","stop_stack","start_stack","list_stacks","update_stack","secrets"]
|
actions = ["delete_stack","create_stack","stop_stack","start_stack","list_stacks","update_stack","secrets","print_all_data","list_endpoints","list_containers","stop_containers","start_containers","refresh_environment","refresh_status","update_status"]
|
||||||
print("Possible actions: ")
|
print("Possible actions: ")
|
||||||
i = 1
|
i = 1
|
||||||
for a in actions:
|
for a in actions:
|
||||||
@@ -137,6 +137,10 @@ if __name__ == "__main__":
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if args.action == "delete_stack":
|
if args.action == "delete_stack":
|
||||||
|
if args.endpoint_id == None:
|
||||||
|
args.endpoint_id = input("Endpoint ID is required for deleting stacks : ")
|
||||||
|
if args.stack == None:
|
||||||
|
args.stack = input("Stack name or ID is required for deleting stacks : ")
|
||||||
por.delete_stack(args.endpoint_id, args.stack,)
|
por.delete_stack(args.endpoint_id, args.stack,)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
@@ -157,24 +161,24 @@ if __name__ == "__main__":
|
|||||||
print(json.dumps(por.all_data,indent=2))
|
print(json.dumps(por.all_data,indent=2))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if args.list_containers:
|
if args.action == "list_containers":
|
||||||
print("Getting containers")
|
print("Getting containers")
|
||||||
por.get_containers(args.endpoint_id,args.stack)
|
por.get_containers(args.endpoint_id,args.stack)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if args.update_stack:
|
if args.action == "update_stack":
|
||||||
print("Updating stacks")
|
print("Updating stacks")
|
||||||
autostart=True if args.autostart else False
|
autostart=True if args.autostart else False
|
||||||
por.update_stack(args.endpoint_id,args.stack,autostart)
|
por.update_stack(args.endpoint_id,args.stack,autostart)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if args.print_all_data:
|
if args.action == "print_all_data":
|
||||||
print(json.dumps(por.all_data,indent=2))
|
print(json.dumps(por.all_data,indent=2))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if args.update_status:
|
if args.action == "update_status":
|
||||||
por.update_status(args.endpoint_id,args.stack)
|
por.update_status(args.endpoint_id,args.stack)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if args.list_endpoints:
|
if args.action == "list_endpoints":
|
||||||
eps = por.get_endpoints()
|
eps = por.get_endpoints()
|
||||||
data = []
|
data = []
|
||||||
for i in eps["by_id"]:
|
for i in eps["by_id"]:
|
||||||
@@ -183,8 +187,8 @@ if __name__ == "__main__":
|
|||||||
print(tabulate(data, headers=headers, tablefmt="github"))
|
print(tabulate(data, headers=headers, tablefmt="github"))
|
||||||
|
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if args.stop_containers:
|
if args.action == "stop_containers":
|
||||||
if por.all_data["endpoints_status"][args.endpoint_id] != 1:
|
if por.all_data["endpoints_status"][args.endpoint_id] != 1:
|
||||||
print(f"Endpoint {por.get_endpoint_name(args.endpoint_id)} is offline")
|
print(f"Endpoint {por.get_endpoint_name(args.endpoint_id)} is offline")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
@@ -195,8 +199,8 @@ if __name__ == "__main__":
|
|||||||
cont+=por.all_data["containers"][args.endpoint_id][c]
|
cont+=por.all_data["containers"][args.endpoint_id][c]
|
||||||
por.stop_containers(args.endpoint_id,cont)
|
por.stop_containers(args.endpoint_id,cont)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if args.start_containers:
|
if args.action == "start_containers":
|
||||||
print("Starting containers")
|
print("Starting containers")
|
||||||
cont = []
|
cont = []
|
||||||
#input(json.dumps(por.all_data,indent=2))
|
#input(json.dumps(por.all_data,indent=2))
|
||||||
@@ -205,7 +209,7 @@ if __name__ == "__main__":
|
|||||||
cont+=por.all_data["containers"][args.endpoint_id][c]
|
cont+=por.all_data["containers"][args.endpoint_id][c]
|
||||||
por.start_containers(args.endpoint_id,cont)
|
por.start_containers(args.endpoint_id,cont)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if args.start_containers:
|
if args.action == "start_containers":
|
||||||
print("Starting containers")
|
print("Starting containers")
|
||||||
cont = []
|
cont = []
|
||||||
#input(json.dumps(por.all_data,indent=2))
|
#input(json.dumps(por.all_data,indent=2))
|
||||||
@@ -214,11 +218,11 @@ if __name__ == "__main__":
|
|||||||
cont+=por.all_data["containers"][args.endpoint_id][c]
|
cont+=por.all_data["containers"][args.endpoint_id][c]
|
||||||
por.start_containers(args.endpoint_id,cont)
|
por.start_containers(args.endpoint_id,cont)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if args.refresh_environment:
|
if args.action == "refresh_environment":
|
||||||
cont = por.refresh()
|
cont = por.refresh()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if args.refresh_status:
|
if args.action == "refresh_status":
|
||||||
if args.stack== "all":
|
if args.stack== "all":
|
||||||
print("Stopping all stacks...")
|
print("Stopping all stacks...")
|
||||||
stcks = por.get_stacks(base, token, endpoint_id=args.endpoint_id)
|
stcks = por.get_stacks(base, token, endpoint_id=args.endpoint_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user