This commit is contained in:
parent
0c884e01cf
commit
84571f1692
4 changed files with 68 additions and 12 deletions
|
@ -104,6 +104,22 @@ class DockgeConnection:
|
|||
def restart(self, name):
|
||||
ret = self._sio.call("agent", ("", "restartStack", name), timeout=10)
|
||||
return ret
|
||||
|
||||
def update(self, name):
|
||||
ret = self._sio.call("agent", ("", "updateStack", name), timeout=10)
|
||||
return ret
|
||||
|
||||
def stop(self, name):
|
||||
ret = self._sio.call("agent", ("", "stopStack", name), timeout=10)
|
||||
return ret
|
||||
|
||||
def start(self, name):
|
||||
ret = self._sio.call("agent", ("", "startStack", name), timeout=10)
|
||||
return ret
|
||||
|
||||
def down(self, name):
|
||||
ret = self._sio.call("agent", ("", "downStack", name), timeout=10)
|
||||
return ret
|
||||
|
||||
def disconnect(self):
|
||||
self._sio.emit("logout")
|
||||
|
|
|
@ -2,10 +2,15 @@ from getpass import getpass
|
|||
from urllib.parse import urlparse
|
||||
|
||||
from . import storage
|
||||
from .utils import display_help, stack_formatter, status_formatter, restart_formatter
|
||||
from .utils import display_help, stack_formatter, status_formatter, generic_formatter
|
||||
from .parser import Credentials, credentialparser
|
||||
from .communicate import DockgeConnection
|
||||
|
||||
def setup():
|
||||
con = DockgeConnection()
|
||||
con.connect_and_login()
|
||||
return con
|
||||
|
||||
def exec_command(command, extra_args):
|
||||
match command:
|
||||
case "help":
|
||||
|
@ -33,27 +38,47 @@ def exec_command(command, extra_args):
|
|||
case "exit":
|
||||
storage.clear()
|
||||
case "list":
|
||||
con = DockgeConnection()
|
||||
con.connect_and_login()
|
||||
con = setup()
|
||||
stack_formatter(con.list_stacks())
|
||||
con.disconnect()
|
||||
case "status":
|
||||
if extra_args is None:
|
||||
raise ValueError
|
||||
con = DockgeConnection()
|
||||
con.connect_and_login()
|
||||
con = setup()
|
||||
status_formatter(con.list_stack(extra_args[0]))
|
||||
con.disconnect()
|
||||
case "restart":
|
||||
if extra_args is None:
|
||||
raise ValueError
|
||||
con = DockgeConnection()
|
||||
con.connect_and_login()
|
||||
restart_formatter(con.restart(extra_args[0]))
|
||||
con = setup()
|
||||
generic_formatter(con.restart(extra_args[0]))
|
||||
con.disconnect()
|
||||
case "update":
|
||||
if extra_args is None:
|
||||
raise ValueError
|
||||
con = setup()
|
||||
generic_formatter(con.update(extra_args[0]))
|
||||
con.disconnect()
|
||||
case "stop":
|
||||
if extra_args is None:
|
||||
raise ValueError
|
||||
con = setup()
|
||||
generic_formatter(con.stop(extra_args[0]))
|
||||
con.disconnect()
|
||||
case "start":
|
||||
if extra_args is None:
|
||||
raise ValueError
|
||||
con = setup()
|
||||
generic_formatter(con.start(extra_args[0]))
|
||||
con.disconnect()
|
||||
case "down":
|
||||
if extra_args is None:
|
||||
raise ValueError
|
||||
con = setup()
|
||||
generic_formatter(con.down(extra_args[0]))
|
||||
con.disconnect()
|
||||
case "debug":
|
||||
con = DockgeConnection()
|
||||
con.connect_and_login()
|
||||
con = setup()
|
||||
stack_formatter(con.list_stacks())
|
||||
print("fgo-ta-com", con.list_stack("fgo-ta-com"))
|
||||
con.disconnect()
|
||||
|
|
|
@ -25,6 +25,6 @@ def status_formatter(status):
|
|||
table = [[k, v] for k, v in status["serviceStatusList"].items()]
|
||||
print(tabulate(table, headers=headers, tablefmt="github"), "\n")
|
||||
|
||||
def restart_formatter(status):
|
||||
def generic_formatter(status):
|
||||
print(f"Is Ok? {'Yes' if status['ok'] else 'No'}")
|
||||
print(f"Stack status: {status['msg']}")
|
||||
|
|
|
@ -34,6 +34,21 @@ cmd_restart = CommandListing(
|
|||
description="Restarts a given stack",
|
||||
)
|
||||
|
||||
cmd_start = CommandListing(
|
||||
command="start",
|
||||
description="Starts a given stack",
|
||||
)
|
||||
|
||||
cmd_stop = CommandListing(
|
||||
command="stop",
|
||||
description="Stops a given stack",
|
||||
)
|
||||
|
||||
cmd_down = CommandListing(
|
||||
command="down",
|
||||
description="Stop & Downs a given stack",
|
||||
)
|
||||
|
||||
cmd_update = CommandListing(
|
||||
command="update",
|
||||
description="Updates a stack",
|
||||
|
@ -54,5 +69,5 @@ cmd_help = CommandListing(
|
|||
description="Displays helping hints for commands",
|
||||
)
|
||||
|
||||
commandlist = [cmd_host, cmd_login, cmd_logout, cmd_list, cmd_restart, cmd_update, cmd_exit, cmd_debug, cmd_help, cmd_status]
|
||||
commandlist = [cmd_host, cmd_login, cmd_logout, cmd_list, cmd_restart, cmd_update, cmd_exit, cmd_debug, cmd_help, cmd_status, cmd_start, cmd_stop, cmd_down]
|
||||
commands = { k.command: k for k in commandlist }
|
||||
|
|
Loading…
Reference in a new issue