added restarting and rebooting miner backends

This commit is contained in:
UpstreamData
2022-05-06 15:52:21 -06:00
parent 8215d33241
commit 267c388a95
6 changed files with 82 additions and 21 deletions

View File

@@ -3,7 +3,7 @@ import asyncio
import sys
from tools.cfg_util.cfg_util_qt.imgs import FAULT_LIGHT, TkImages
from tools.cfg_util.cfg_util_qt.scan import btn_scan
from tools.cfg_util.cfg_util_qt.commands import btn_light
from tools.cfg_util.cfg_util_qt.commands import btn_light, btn_reboot, btn_backend
from tools.cfg_util.cfg_util_qt.configure import (
generate_config_ui,
btn_import,
@@ -27,7 +27,7 @@ async def main():
window["scan_table"].Widget.column(2, anchor=tk.W)
# cmd table sort event
window["cmd_table"].Widget.bind("<Button-1>", lambda x: print("clicked"))
# window["cmd_table"].Widget.bind("<Button-1>", lambda x: print("clicked"))
while True:
event, value = window.read(0)
@@ -94,11 +94,18 @@ async def main():
if event == "cmd_all":
_table = "cmd_table"
btn_all(_table, value[_table])
if event == "cmd_light":
_table = "cmd_table"
_ips = value[_table]
asyncio.create_task(btn_light(_ips))
if event == "cmd_reboot":
_table = "cmd_table"
_ips = value[_table]
asyncio.create_task(btn_reboot(_ips))
if event == "cmd_backend":
_table = "cmd_table"
_ips = value[_table]
asyncio.create_task(btn_backend(_ips))
if event == "__TIMEOUT__":
await asyncio.sleep(0)

View File

@@ -5,11 +5,11 @@ from tools.cfg_util.cfg_util_qt.decorators import disable_buttons
@disable_buttons
async def btn_light(ips: list):
async def btn_light(ip_idxs: list):
table_manager = TableManager()
_table = window["cmd_table"].Widget
iids = _table.get_children()
for idx in ips:
for idx in ip_idxs:
item = _table.item(iids[idx])
ip = item["values"][0]
new_light_val = not table_manager.data[ip]["Light"]
@@ -24,3 +24,39 @@ async def btn_light(ips: list):
else:
table_manager.data[ip]["Command Output"] = "Fault Light command failed."
table_manager.update_tables()
@disable_buttons
async def btn_reboot(ip_idxs: list):
table_manager = TableManager()
_table = window["cmd_table"].Widget
iids = _table.get_children()
for idx in ip_idxs:
item = _table.item(iids[idx])
ip = item["values"][0]
miner = await MinerFactory().get_miner(ip)
success = await miner.reboot()
if success:
table_manager.data[ip]["Command Output"] = "Reboot command succeeded."
else:
table_manager.data[ip]["Command Output"] = "Reboot command failed."
table_manager.update_tables()
@disable_buttons
async def btn_backend(ip_idxs: list):
table_manager = TableManager()
_table = window["cmd_table"].Widget
iids = _table.get_children()
for idx in ip_idxs:
item = _table.item(iids[idx])
ip = item["values"][0]
miner = await MinerFactory().get_miner(ip)
success = await miner.restart_backend()
if success:
table_manager.data[ip][
"Command Output"
] = "Restart Backend command succeeded."
else:
table_manager.data[ip]["Command Output"] = "Restart Backend command failed."
table_manager.update_tables()