added restarting and rebooting miner backends
This commit is contained in:
@@ -81,10 +81,10 @@ class BaseMiner:
|
||||
return None
|
||||
|
||||
async def reboot(self):
|
||||
return None
|
||||
return False
|
||||
|
||||
async def restart_backend(self):
|
||||
return None
|
||||
return False
|
||||
|
||||
async def send_config(self, yaml_config):
|
||||
return None
|
||||
|
||||
@@ -114,10 +114,13 @@ class BMMiner(BaseMiner):
|
||||
pool_data.append({"url": pool["URL"], "user": pool["User"], "pwd": "123"})
|
||||
return pool_data
|
||||
|
||||
async def reboot(self) -> None:
|
||||
async def reboot(self) -> bool:
|
||||
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.")
|
||||
if isinstance(_ret, str):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def get_data(self):
|
||||
data = {
|
||||
|
||||
@@ -65,20 +65,26 @@ class BOSMiner(BaseMiner):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def restart_backend(self) -> None:
|
||||
await self.restart_bosminer()
|
||||
async def restart_backend(self) -> bool:
|
||||
return await self.restart_bosminer()
|
||||
|
||||
async def restart_bosminer(self) -> None:
|
||||
async def restart_bosminer(self) -> bool:
|
||||
"""Restart bosminer hashing process."""
|
||||
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.")
|
||||
if isinstance(_ret, str):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def reboot(self) -> None:
|
||||
async def reboot(self) -> bool:
|
||||
"""Reboots power to the physical miner."""
|
||||
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.")
|
||||
if isinstance(_ret, str):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def get_config(self) -> None:
|
||||
logging.debug(f"{self}: Getting config.")
|
||||
|
||||
@@ -2,6 +2,7 @@ from miners import BaseMiner
|
||||
from API.cgminer import CGMinerAPI
|
||||
from API import APIError
|
||||
from settings import MINER_FACTORY_GET_VERSION_RETRIES as DATA_RETRIES
|
||||
import logging
|
||||
|
||||
|
||||
class CGMiner(BaseMiner):
|
||||
@@ -56,16 +57,24 @@ class CGMiner(BaseMiner):
|
||||
continue
|
||||
return result
|
||||
|
||||
async def restart_backend(self) -> None:
|
||||
await self.restart_cgminer()
|
||||
async def restart_backend(self) -> bool:
|
||||
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 = ";".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:
|
||||
await self.send_ssh_command("reboot")
|
||||
async def reboot(self) -> bool:
|
||||
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:
|
||||
commands = [
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user