added more logging for bosminer models.

This commit is contained in:
UpstreamData
2022-03-15 09:07:07 -06:00
parent 07a8b00a93
commit 9edcd866bb
4 changed files with 51 additions and 16 deletions

View File

@@ -39,7 +39,7 @@ class BMMiner(BaseMiner):
else:
logging.warning(f"Failed to get hostname for miner: {self}")
return "?"
except Exception:
except Exception as e:
logging.warning(f"Failed to get hostname for miner: {self}")
return "?"
@@ -85,3 +85,4 @@ class BMMiner(BaseMiner):
async def reboot(self) -> None:
logging.debug(f"{self}: Sending reboot command.")
await self.send_ssh_command("reboot")
logging.debug(f"{self}: Reboot command completed.")

View File

@@ -3,7 +3,7 @@ from API.bosminer import BOSMinerAPI
import asyncssh
import toml
from config.bos import bos_config_convert, general_config_convert_bos
import logging
class BOSMiner(BaseMiner):
def __init__(self, ip: str) -> None:
@@ -23,8 +23,11 @@ class BOSMiner(BaseMiner):
try:
conn = await asyncssh.connect(str(self.ip), known_hosts=None, username=self.uname, password=self.pwd,
server_host_key_algs=['ssh-rsa'])
except OSError:
logging.warning(f"Connection refused: {self} ")
return None
except Exception as e:
print("Exception raised:", self.ip)
logging.warning(f"{self} raised an exception: {e}")
raise e
# return created connection
return conn
@@ -42,7 +45,7 @@ class BOSMiner(BaseMiner):
# save result of the command
result = await conn.run(cmd)
except Exception as e:
print(f"{cmd} error: {e}")
logging.warning(f"{self} command {cmd} error: {e}")
if i == 3:
return
continue
@@ -51,28 +54,40 @@ class BOSMiner(BaseMiner):
async def fault_light_on(self) -> None:
"""Sends command to turn on fault light on the miner."""
logging.debug(f"{self}: Sending fault_light on command.")
await self.send_ssh_command('miner fault_light on')
logging.debug(f"{self}: fault_light on command completed.")
async def fault_light_off(self) -> None:
"""Sends command to turn off fault light on the miner."""
logging.debug(f"{self}: Sending fault_light off command.")
await self.send_ssh_command('miner fault_light off')
logging.debug(f"{self}: fault_light off command completed.")
async def restart_backend(self):
await self.restart_bosminer()
async def restart_bosminer(self) -> None:
"""Restart bosminer hashing process."""
logging.debug(f"{self}: Sending bosminer restart command.")
await self.send_ssh_command('/etc/init.d/bosminer restart')
logging.debug(f"{self}: bosminer restart command completed.")
async def reboot(self) -> None:
"""Reboots power to the physical miner."""
await self.send_ssh_command('/sbin/reboot')
logging.debug(f"{self}: Sending reboot command.")
await self.send_ssh_command("/sbin/reboot")
logging.debug(f"{self}: Reboot command completed.")
async def get_config(self) -> None:
logging.debug(f"{self}: Getting config.")
async with (await self._get_ssh_connection()) as conn:
logging.debug(f"{self}: Opening SFTP connection.")
async with conn.start_sftp_client() as sftp:
logging.debug(f"{self}: Reading config file.")
async with sftp.open('/etc/bosminer.toml') as file:
toml_data = toml.loads(await file.read())
logging.debug(f"{self}: Converting config file.")
cfg = await bos_config_convert(toml_data)
self.config = cfg
@@ -80,33 +95,47 @@ class BOSMiner(BaseMiner):
"""Attempts to get hostname from miner."""
try:
async with (await self._get_ssh_connection()) as conn:
data = await conn.run('cat /proc/sys/kernel/hostname')
return data.stdout.strip()
if conn is not None:
data = await conn.run('cat /proc/sys/kernel/hostname')
host = data.stdout.strip()
logging.debug(f"Found hostname for {self.ip}: {host}")
return host
else:
logging.warning(f"Failed to get hostname for miner: {self}")
return "?"
except Exception as e:
print(self.ip, e)
return "BOSMiner Unknown"
logging.warning(f"Failed to get hostname for miner: {self}")
return "?"
async def get_model(self):
if self.model:
logging.debug(f"Found model for {self.ip}: {self.model} (BOS)")
return self.model + " (BOS)"
version_data = await self.api.devdetails()
if version_data:
if not version_data["DEVDETAILS"] == []:
self.model = version_data["DEVDETAILS"][0]["Model"].replace("Antminer ", "")
logging.debug(f"Found model for {self.ip}: {self.model} (BOS)")
return self.model + " (BOS)"
logging.warning(f"Failed to get model for miner: {self}")
return None
async def send_config(self, yaml_config) -> None:
"""Configures miner with yaml config."""
logging.debug(f"{self}: Sending config.")
toml_conf = await general_config_convert_bos(yaml_config)
async with (await self._get_ssh_connection()) as conn:
logging.debug(f"{self}: Opening SFTP connection.")
async with conn.start_sftp_client() as sftp:
logging.debug(f"{self}: Opening config file.")
async with sftp.open('/etc/bosminer.toml', 'w+') as file:
await file.write(toml_conf)
logging.debug(f"{self}: Restarting BOSMiner")
await conn.run("/etc/init.d/bosminer restart")
async def get_board_info(self) -> dict:
"""Gets data on each board and chain in the miner."""
logging.debug(f"{self}: Getting board info.")
devdetails = await self.api.devdetails()
if not devdetails.get("DEVDETAILS"):
print("devdetails error", devdetails)
@@ -126,6 +155,7 @@ class BOSMiner(BaseMiner):
"chip_status": "o" * board['Chips'],
"nominal": nominal
})
logging.debug(f"Found board data for {self}: {boards}")
return boards
async def get_bad_boards(self) -> dict: