Merge pull request #3 from Dellsauce/master
added comments and docstrings to some files
This commit is contained in:
@@ -135,7 +135,7 @@ class BaseMinerAPI:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def load_api_data(data: bytes) -> None:
|
||||
def load_api_data(data: bytes) -> dict:
|
||||
"""Convert API data from JSON to dict"""
|
||||
try:
|
||||
# some json from the API returns with a null byte (\x00) on the end
|
||||
@@ -148,3 +148,4 @@ class BaseMinerAPI:
|
||||
# handle bad json
|
||||
except json.decoder.JSONDecodeError:
|
||||
raise APIError(f"Decode Error: {data}")
|
||||
return data
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
from API.bmminer import BMMinerAPI
|
||||
from API.bosminer import BOSMinerAPI
|
||||
from API.cgminer import CGMinerAPI
|
||||
from API.unknown import UnknownAPI
|
||||
import ipaddress
|
||||
|
||||
|
||||
class BaseMiner:
|
||||
def __init__(self, ip: str, api: BMMinerAPI or BOSMinerAPI or CGMinerAPI) -> None:
|
||||
def __init__(self, ip: str, api: BMMinerAPI or BOSMinerAPI or CGMinerAPI or UnknownAPI) -> None:
|
||||
self.ip = ipaddress.ip_address(ip)
|
||||
self.api = api
|
||||
|
||||
@@ -4,6 +4,7 @@ import asyncssh
|
||||
import toml
|
||||
from config.bos import bos_config_convert, general_config_convert_bos
|
||||
|
||||
|
||||
class BOSminer(BaseMiner):
|
||||
def __init__(self, ip: str) -> None:
|
||||
api = BOSMinerAPI(ip)
|
||||
@@ -23,16 +24,23 @@ class BOSminer(BaseMiner):
|
||||
return conn
|
||||
|
||||
async def send_ssh_command(self, cmd: str) -> None:
|
||||
"""Sends SSH command to miner."""
|
||||
# creates result variable
|
||||
result = None
|
||||
|
||||
# runs the command on the miner
|
||||
async with (await self._get_ssh_connection()) as conn:
|
||||
# attempt to run command up to 3 times
|
||||
for i in range(3):
|
||||
try:
|
||||
# save result of the command
|
||||
result = await conn.run(cmd)
|
||||
except Exception as e:
|
||||
print(f"{cmd} error: {e}")
|
||||
if i == 3:
|
||||
return
|
||||
continue
|
||||
|
||||
# let the user know the result of the command
|
||||
if result is not None:
|
||||
if result.stdout != "":
|
||||
@@ -45,15 +53,19 @@ class BOSminer(BaseMiner):
|
||||
print(cmd)
|
||||
|
||||
async def fault_light_on(self) -> None:
|
||||
"""Sends command to turn on fault light on the miner."""
|
||||
await self.send_ssh_command('miner fault_light on')
|
||||
|
||||
async def fault_light_off(self) -> None:
|
||||
"""Sends command to turn off fault light on the miner."""
|
||||
await self.send_ssh_command('miner fault_light off')
|
||||
|
||||
async def restart_backend(self) -> None:
|
||||
"""Restart bosminer hashing process."""
|
||||
await self.send_ssh_command('/etc/init.d/bosminer restart')
|
||||
|
||||
async def reboot(self) -> None:
|
||||
"""Reboots power to the physical miner."""
|
||||
await self.send_ssh_command('/sbin/reboot')
|
||||
|
||||
async def get_config(self) -> None:
|
||||
@@ -65,6 +77,7 @@ class BOSminer(BaseMiner):
|
||||
self.config = cfg
|
||||
|
||||
async def get_hostname(self) -> str:
|
||||
"""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')
|
||||
@@ -74,6 +87,7 @@ class BOSminer(BaseMiner):
|
||||
return "BOSMiner Unknown"
|
||||
|
||||
async def send_config(self, yaml_config) -> None:
|
||||
"""Configures miner with yaml config."""
|
||||
toml_conf = await general_config_convert_bos(yaml_config)
|
||||
async with (await self._get_ssh_connection()) as conn:
|
||||
async with conn.start_sftp_client() as sftp:
|
||||
@@ -82,6 +96,7 @@ class BOSminer(BaseMiner):
|
||||
await conn.run("/etc/init.d/bosminer restart")
|
||||
|
||||
async def get_bad_boards(self) -> list:
|
||||
"""Checks for and provides list of non working boards."""
|
||||
devs = await self.api.devdetails()
|
||||
bad = 0
|
||||
chains = devs['DEVDETAILS']
|
||||
@@ -92,6 +107,7 @@ class BOSminer(BaseMiner):
|
||||
return [str(self.ip), bad]
|
||||
|
||||
async def check_good_boards(self) -> str:
|
||||
"""Checks for and provides list for working boards."""
|
||||
devs = await self.api.devdetails()
|
||||
bad = 0
|
||||
chains = devs['DEVDETAILS']
|
||||
|
||||
Reference in New Issue
Block a user