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

@@ -81,10 +81,10 @@ class BaseMiner:
return None return None
async def reboot(self): async def reboot(self):
return None return False
async def restart_backend(self): async def restart_backend(self):
return None return False
async def send_config(self, yaml_config): async def send_config(self, yaml_config):
return None return None

View File

@@ -114,10 +114,13 @@ class BMMiner(BaseMiner):
pool_data.append({"url": pool["URL"], "user": pool["User"], "pwd": "123"}) pool_data.append({"url": pool["URL"], "user": pool["User"], "pwd": "123"})
return pool_data return pool_data
async def reboot(self) -> None: async def reboot(self) -> bool:
logging.debug(f"{self}: Sending reboot command.") logging.debug(f"{self}: Sending reboot command.")
await self.send_ssh_command("reboot") _ret = await self.send_ssh_command("reboot")
logging.debug(f"{self}: Reboot command completed.") logging.debug(f"{self}: Reboot command completed.")
if isinstance(_ret, str):
return True
return False
async def get_data(self): async def get_data(self):
data = { data = {

View File

@@ -65,20 +65,26 @@ class BOSMiner(BaseMiner):
return True return True
return False return False
async def restart_backend(self) -> None: async def restart_backend(self) -> bool:
await self.restart_bosminer() return await self.restart_bosminer()
async def restart_bosminer(self) -> None: async def restart_bosminer(self) -> bool:
"""Restart bosminer hashing process.""" """Restart bosminer hashing process."""
logging.debug(f"{self}: Sending bosminer restart command.") logging.debug(f"{self}: Sending bosminer restart command.")
await self.send_ssh_command("/etc/init.d/bosminer restart") _ret = await self.send_ssh_command("/etc/init.d/bosminer restart")
logging.debug(f"{self}: bosminer restart command completed.") logging.debug(f"{self}: bosminer restart command completed.")
if isinstance(_ret, str):
return True
return False
async def reboot(self) -> None: async def reboot(self) -> bool:
"""Reboots power to the physical miner.""" """Reboots power to the physical miner."""
logging.debug(f"{self}: Sending reboot command.") logging.debug(f"{self}: Sending reboot command.")
await self.send_ssh_command("/sbin/reboot") _ret = await self.send_ssh_command("/sbin/reboot")
logging.debug(f"{self}: Reboot command completed.") logging.debug(f"{self}: Reboot command completed.")
if isinstance(_ret, str):
return True
return False
async def get_config(self) -> None: async def get_config(self) -> None:
logging.debug(f"{self}: Getting config.") logging.debug(f"{self}: Getting config.")

View File

@@ -2,6 +2,7 @@ from miners import BaseMiner
from API.cgminer import CGMinerAPI from API.cgminer import CGMinerAPI
from API import APIError from API import APIError
from settings import MINER_FACTORY_GET_VERSION_RETRIES as DATA_RETRIES from settings import MINER_FACTORY_GET_VERSION_RETRIES as DATA_RETRIES
import logging
class CGMiner(BaseMiner): class CGMiner(BaseMiner):
@@ -56,16 +57,24 @@ class CGMiner(BaseMiner):
continue continue
return result return result
async def restart_backend(self) -> None: async def restart_backend(self) -> bool:
await self.restart_cgminer() return await self.restart_cgminer()
async def restart_cgminer(self) -> None: async def restart_cgminer(self) -> bool:
commands = ["cgminer-api restart", "/usr/bin/cgminer-monitor >/dev/null 2>&1"] commands = ["cgminer-api restart", "/usr/bin/cgminer-monitor >/dev/null 2>&1"]
commands = ";".join(commands) commands = ";".join(commands)
await self.send_ssh_command(commands) _ret = await self.send_ssh_command(commands)
if isinstance(_ret, str):
return True
return False
async def reboot(self) -> None: async def reboot(self) -> bool:
await self.send_ssh_command("reboot") logging.debug(f"{self}: Sending reboot command.")
_ret = await self.send_ssh_command("reboot")
logging.debug(f"{self}: Reboot command completed.")
if isinstance(_ret, str):
return True
return False
async def start_cgminer(self) -> None: async def start_cgminer(self) -> None:
commands = [ commands = [

View File

@@ -3,7 +3,7 @@ import asyncio
import sys import sys
from tools.cfg_util.cfg_util_qt.imgs import FAULT_LIGHT, TkImages 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.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 ( from tools.cfg_util.cfg_util_qt.configure import (
generate_config_ui, generate_config_ui,
btn_import, btn_import,
@@ -27,7 +27,7 @@ async def main():
window["scan_table"].Widget.column(2, anchor=tk.W) window["scan_table"].Widget.column(2, anchor=tk.W)
# cmd table sort event # 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: while True:
event, value = window.read(0) event, value = window.read(0)
@@ -94,11 +94,18 @@ async def main():
if event == "cmd_all": if event == "cmd_all":
_table = "cmd_table" _table = "cmd_table"
btn_all(_table, value[_table]) btn_all(_table, value[_table])
if event == "cmd_light": if event == "cmd_light":
_table = "cmd_table" _table = "cmd_table"
_ips = value[_table] _ips = value[_table]
asyncio.create_task(btn_light(_ips)) 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__": if event == "__TIMEOUT__":
await asyncio.sleep(0) await asyncio.sleep(0)

View File

@@ -5,11 +5,11 @@ from tools.cfg_util.cfg_util_qt.decorators import disable_buttons
@disable_buttons @disable_buttons
async def btn_light(ips: list): async def btn_light(ip_idxs: list):
table_manager = TableManager() table_manager = TableManager()
_table = window["cmd_table"].Widget _table = window["cmd_table"].Widget
iids = _table.get_children() iids = _table.get_children()
for idx in ips: for idx in ip_idxs:
item = _table.item(iids[idx]) item = _table.item(iids[idx])
ip = item["values"][0] ip = item["values"][0]
new_light_val = not table_manager.data[ip]["Light"] new_light_val = not table_manager.data[ip]["Light"]
@@ -24,3 +24,39 @@ async def btn_light(ips: list):
else: else:
table_manager.data[ip]["Command Output"] = "Fault Light command failed." table_manager.data[ip]["Command Output"] = "Fault Light command failed."
table_manager.update_tables() 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()