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