added some docstrings to API, and added to miner types

This commit is contained in:
UpstreamData
2021-12-20 11:55:30 -07:00
parent b58d3cbb9b
commit 449bdfae69
10 changed files with 220 additions and 9 deletions

View File

@@ -6,145 +6,207 @@ class BMMinerAPI(BaseMinerAPI):
super().__init__(ip, port)
async def version(self) -> dict:
"""
API 'version' command.
Returns a dict containing version information.
"""
return await self.send_command("version")
async def config(self) -> dict:
"""
API 'config' command.
Returns some miner configuration information:
ASC Count <- the number of ASCs
PGA Count <- the number of PGAs
Pool Count <- the number of Pools
Strategy <- the current pool strategy
Log Interval <- the interval of logging
Device Code <- list of compiled device drivers
OS <- the current operating system
Failover-Only <- failover-only setting
Scan Time <- scan-time setting
Queue <- queue setting
Expiry <- expiry setting
"""
return await self.send_command("config")
async def summary(self) -> dict:
"""API 'summary' command."""
return await self.send_command("summary")
async def pools(self) -> dict:
"""API 'pools' command."""
return await self.send_command("pools")
async def devs(self) -> dict:
"""API 'devs' command."""
return await self.send_command("devs")
async def edevs(self, old: bool = False) -> dict:
"""API 'edevs' command."""
if old:
return await self.send_command("edevs", parameters="old")
else:
return await self.send_command("edevs")
async def pga(self, n: int) -> dict:
"""API 'pga' command."""
return await self.send_command("pga", parameters=n)
async def pgacount(self) -> dict:
"""API 'pgacount' command."""
return await self.send_command("pgacount")
async def switchpool(self, n: int) -> dict:
"""API 'switchpool' command."""
return await self.send_command("switchpool", parameters=n)
async def enablepool(self, n: int) -> dict:
"""API 'enablepool' command."""
return await self.send_command("enablepool", parameters=n)
async def addpool(self, url: str, username: str, password: str) -> dict:
"""API 'addpool' command."""
return await self.send_command("addpool", parameters=f"{url}, {username}, {password}")
async def poolpriority(self, *n: int) -> dict:
"""API 'poolpriority' command."""
return await self.send_command("poolpriority", parameters=f"{','.join([str(item) for item in n])}")
async def poolquota(self, n: int, q: int) -> dict:
"""API 'poolquota' command."""
return await self.send_command("poolquota", parameters=f"{n}, {q}")
async def disablepool(self, n: int) -> dict:
"""API 'disablepool' command."""
return await self.send_command("disablepool", parameters=n)
async def removepool(self, n: int) -> dict:
"""API 'removepool' command."""
return await self.send_command("removepool", parameters=n)
async def save(self, filename: str = None) -> dict:
"""API 'save' command."""
if filename:
return await self.send_command("save", parameters=filename)
else:
return await self.send_command("save")
async def quit(self) -> dict:
"""quit' command."""
return await self.send_command("quit")
async def notify(self) -> dict:
"""API 'notify' command."""
return await self.send_command("notify")
async def privileged(self) -> dict:
"""API 'privileged' command."""
return await self.send_command("privileged")
async def pgaenable(self, n: int) -> dict:
"""API 'pgaenable' command."""
return await self.send_command("pgaenable", parameters=n)
async def pgadisable(self, n: int) -> dict:
"""API 'pgadisable' command."""
return await self.send_command("pgadisable", parameters=n)
async def pgaidentify(self, n: int) -> dict:
"""API 'pgaidentify' command."""
return await self.send_command("pgaidentify", parameters=n)
async def devdetails(self) -> dict:
"""API 'devdetails' command."""
return await self.send_command("devdetails")
async def restart(self) -> dict:
"""API 'restart' command."""
return await self.send_command("restart")
async def stats(self) -> dict:
"""API 'stats' command."""
return await self.send_command("stats")
async def estats(self, old: bool = False) -> dict:
"""API 'estats' command."""
if old:
return await self.send_command("estats", parameters="old")
else:
return await self.send_command("estats")
async def check(self, command) -> dict:
"""API 'check' command."""
return await self.send_command("check", parameters=command)
async def failover_only(self, failover: bool) -> dict:
"""API 'failover-only' command."""
return await self.send_command("failover-only", parameters=failover)
async def coin(self) -> dict:
"""API 'coin' command."""
return await self.send_command("coin")
async def debug(self, setting: str) -> dict:
"""API 'debug' command."""
return await self.send_command("debug", parameters=setting)
async def setconfig(self, name: str, n: int) -> dict:
"""API 'setconfig' command."""
return await self.send_command("setconfig", parameters=f"{name}, {n}")
async def usbstats(self) -> dict:
"""API 'usbstats' command."""
return await self.send_command("usbstats")
async def pgaset(self, n: int, opt: str, val: int = None) -> dict:
"""API 'pgaset' command."""
if val:
return await self.send_command("pgaset", parameters=f"{n}, {opt}, {val}")
else:
return await self.send_command("pgaset", parameters=f"{n}, {opt}")
async def zero(self, which: str, value: bool) -> dict:
"""API 'zero' command."""
return await self.send_command("zero", parameters=f"{which}, {value}")
async def hotplug(self, n: int) -> dict:
"""API 'hotplug' command."""
return await self.send_command("hotplug", parameters=n)
async def asc(self, n: int) -> dict:
"""API 'asc' command."""
return await self.send_command("asc", parameters=n)
async def ascenable(self, n: int) -> dict:
"""API 'ascenable' command."""
return await self.send_command("ascenable", parameters=n)
async def ascdisable(self, n: int) -> dict:
"""API 'ascdisable' command."""
return await self.send_command("ascdisable", parameters=n)
async def ascidentify(self, n: int) -> dict:
"""API 'ascidentify' command."""
return await self.send_command("ascidentify", parameters=n)
async def asccount(self) -> dict:
"""API 'asccount' command."""
return await self.send_command("asccount")
async def ascset(self, n: int, opt: str, val: int = None) -> dict:
"""API 'ascset' command."""
if val:
return await self.send_command("ascset", parameters=f"{n}, {opt}, {val}")
else:
return await self.send_command("ascset", parameters=f"{n}, {opt}")
async def lcd(self) -> dict:
"""API 'lcd' command."""
return await self.send_command("lcd")
async def lockstats(self) -> dict:
"""API 'lockstats' command."""
return await self.send_command("lockstats")

View File

@@ -6,8 +6,28 @@ class CGMinerAPI(BaseMinerAPI):
super().__init__(ip, port)
async def version(self) -> dict:
"""
API 'version' command.
Returns a dict containing version information.
"""
return await self.send_command("version")
async def config(self) -> dict:
"""
API 'config' command.
Returns a dict containing some miner configuration information:
ASC Count <- the number of ASCs
PGA Count <- the number of PGAs
Pool Count <- the number of Pools
Strategy <- the current pool strategy
Log Interval <- the interval of logging
Device Code <- list of compiled device drivers
OS <- the current operating system
"""
return await self.send_command("config")
async def summary(self) -> dict:
return await self.send_command("summary")

View File

@@ -5,7 +5,7 @@ import toml
from config.bos import bos_config_convert, general_config_convert_bos
class BOSminer(BaseMiner):
class BOSMinerS9(BaseMiner):
def __init__(self, ip: str) -> None:
api = BOSMinerAPI(ip)
super().__init__(ip, api)
@@ -14,7 +14,7 @@ class BOSminer(BaseMiner):
self.pwd = 'admin'
def __repr__(self) -> str:
return f"BOSminer: {str(self.ip)}"
return f"S9 - BOSminer: {str(self.ip)}"
async def _get_ssh_connection(self) -> asyncssh.connect:
"""Create a new asyncssh connection"""

View File

@@ -5,7 +5,7 @@ import toml
from config.bos import bos_config_convert, general_config_convert_bos
class BOSminer(BaseMiner):
class BOSminerX17(BaseMiner):
def __init__(self, ip: str) -> None:
api = BOSMinerAPI(ip)
super().__init__(ip, api)
@@ -14,7 +14,7 @@ class BOSminer(BaseMiner):
self.pwd = 'admin'
def __repr__(self) -> str:
return f"BOSminer: {str(self.ip)}"
return f"X17 - BOSminer: {str(self.ip)}"
async def _get_ssh_connection(self) -> asyncssh.connect:
"""Create a new asyncssh connection"""

View File

@@ -0,0 +1,26 @@
from API.btminer import BTMinerAPI
from miners import BaseMiner
class BTMinerM20(BaseMiner):
def __init__(self, ip: str) -> None:
api = BTMinerAPI(ip)
super().__init__(ip, api)
def __repr__(self) -> str:
return f"M20 - BTMiner: {str(self.ip)}"
async def get_hostname(self) -> str:
return "BTMiner Unknown"
async def send_config(self):
return None # ignore for now
async def restart_backend(self) -> None:
return None
async def reboot(self) -> None:
return None
async def get_config(self) -> None:
return None

View File

@@ -0,0 +1,26 @@
from API.btminer import BTMinerAPI
from miners import BaseMiner
class BTMinerM21(BaseMiner):
def __init__(self, ip: str) -> None:
api = BTMinerAPI(ip)
super().__init__(ip, api)
def __repr__(self) -> str:
return f"M21 - BTMiner: {str(self.ip)}"
async def get_hostname(self) -> str:
return "BTMiner Unknown"
async def send_config(self):
return None # ignore for now
async def restart_backend(self) -> None:
return None
async def reboot(self) -> None:
return None
async def get_config(self) -> None:
return None

View File

@@ -0,0 +1,26 @@
from API.btminer import BTMinerAPI
from miners import BaseMiner
class BTMinerM30(BaseMiner):
def __init__(self, ip: str) -> None:
api = BTMinerAPI(ip)
super().__init__(ip, api)
def __repr__(self) -> str:
return f"M30 - BTMiner: {str(self.ip)}"
async def get_hostname(self) -> str:
return "BTMiner Unknown"
async def send_config(self):
return None # ignore for now
async def restart_backend(self) -> None:
return None
async def reboot(self) -> None:
return None
async def get_config(self) -> None:
return None

View File

@@ -0,0 +1,26 @@
from API.btminer import BTMinerAPI
from miners import BaseMiner
class BTMinerM31(BaseMiner):
def __init__(self, ip: str) -> None:
api = BTMinerAPI(ip)
super().__init__(ip, api)
def __repr__(self) -> str:
return f"M31 - BTMiner: {str(self.ip)}"
async def get_hostname(self) -> str:
return "BTMiner Unknown"
async def send_config(self):
return None # ignore for now
async def restart_backend(self) -> None:
return None
async def reboot(self) -> None:
return None
async def get_config(self) -> None:
return None

View File

@@ -0,0 +1,26 @@
from API.btminer import BTMinerAPI
from miners import BaseMiner
class BTMinerM32(BaseMiner):
def __init__(self, ip: str) -> None:
api = BTMinerAPI(ip)
super().__init__(ip, api)
def __repr__(self) -> str:
return f"M32 - BTMiner: {str(self.ip)}"
async def get_hostname(self) -> str:
return "BTMiner Unknown"
async def send_config(self):
return None # ignore for now
async def restart_backend(self) -> None:
return None
async def reboot(self) -> None:
return None
async def get_config(self) -> None:
return None

View File

@@ -1,10 +1,6 @@
import ipaddress
import asyncio
from miners.miner_factory import MinerFactory
from miners.bmminer import BMMiner
from miners.bosminer import BOSminer
from miners.cgminer import CGMiner
from miners.unknown import UnknownMiner
PING_RETRIES: int = 3
PING_TIMEOUT: int = 3
@@ -19,6 +15,7 @@ class MinerNetwork:
self.mask = mask
def get_network(self) -> ipaddress.ip_network:
"""Get the network using the information passed to the MinerNetwork or from cache."""
if self.network:
return self.network
if not self.ip_addr:
@@ -31,7 +28,8 @@ class MinerNetwork:
subnet_mask = "24"
return ipaddress.ip_network(f"{default_gateway}/{subnet_mask}", strict=False)
async def scan_network_for_miners(self) -> None or list[BOSminer or BMMiner or CGMiner or UnknownMiner]:
async def scan_network_for_miners(self) -> None or list:
"""Scan the network for miners, and use the miner factory to get correct types."""
local_network = self.get_network()
print(f"Scanning {local_network} for miners...")
scan_tasks = []
@@ -49,6 +47,7 @@ class MinerNetwork:
@staticmethod
async def ping_miner(ip: ipaddress.ip_address) -> None or ipaddress.ip_address:
"""Send ping requests to a miner."""
for i in range(PING_RETRIES):
connection_fut = asyncio.open_connection(str(ip), 4028)
try: