set up config tool for braiins OS
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
from API.bosminer import BOSMinerAPI
|
||||
from API.cgminer import CGMinerAPI
|
||||
from API.bmminer import BMMinerAPI
|
||||
from API import BaseMinerAPI
|
||||
import ipaddress
|
||||
import typing
|
||||
|
||||
|
||||
class BaseMiner:
|
||||
def __init__(self, ip: str, api: BOSMinerAPI or CGMinerAPI or BMMinerAPI):
|
||||
def __init__(self, ip: str, api: typing.Type[BaseMinerAPI]):
|
||||
self.ip = ipaddress.ip_address(ip)
|
||||
self.api = api
|
||||
|
||||
@@ -9,3 +9,6 @@ class BMMiner(BaseMiner):
|
||||
|
||||
def __repr__(self):
|
||||
return f"BMMiner: {str(self.ip)}"
|
||||
|
||||
async def send_config(self):
|
||||
return None
|
||||
|
||||
@@ -97,3 +97,32 @@ class BOSminer(BaseMiner):
|
||||
if update_config:
|
||||
self.update_config(config)
|
||||
return config
|
||||
|
||||
async def send_config(self, config):
|
||||
toml_conf = toml.dumps(config)
|
||||
async with asyncssh.connect(str(self.ip), known_hosts=None, username='root', password='admin',
|
||||
server_host_key_algs=['ssh-rsa']) as conn:
|
||||
async with conn.start_sftp_client() as sftp:
|
||||
async with sftp.open('/etc/bosminer.toml', 'w+') as file:
|
||||
await file.write(toml_conf)
|
||||
await conn.run("/etc/init.d/bosminer restart")
|
||||
|
||||
async def get_bad_boards(self):
|
||||
devs = await self.api.devdetails()
|
||||
bad = 0
|
||||
chains = devs['DEVDETAILS']
|
||||
for chain in chains:
|
||||
if chain['Chips'] == 0:
|
||||
bad += 1
|
||||
if bad > 0:
|
||||
return (str(self.ip), bad)
|
||||
|
||||
async def check_good_boards(self):
|
||||
devs = await self.api.devdetails()
|
||||
bad = 0
|
||||
chains = devs['DEVDETAILS']
|
||||
for chain in chains:
|
||||
if chain['Chips'] == 0:
|
||||
bad += 1
|
||||
if not bad > 0:
|
||||
return str(self.ip)
|
||||
|
||||
@@ -9,3 +9,6 @@ class CGMiner(BaseMiner):
|
||||
|
||||
def __repr__(self):
|
||||
return f"CGMiner: {str(self.ip)}"
|
||||
|
||||
async def send_config(self):
|
||||
return None
|
||||
|
||||
@@ -6,28 +6,41 @@ from API import APIError
|
||||
import asyncio
|
||||
import ipaddress
|
||||
import json
|
||||
import typing
|
||||
|
||||
|
||||
class MinerFactory:
|
||||
def __init__(self):
|
||||
self.miners = {}
|
||||
|
||||
async def get_miner(self, ip: ipaddress.ip_address):
|
||||
if ip in self.miners:
|
||||
return self.miners[ip]
|
||||
version_data = await self._get_version_data(ip)
|
||||
version = None
|
||||
if version_data:
|
||||
version = list(version_data['VERSION'][0].keys())
|
||||
if version:
|
||||
if "BOSminer" in version or "BOSminer+" in version:
|
||||
return BOSminer(str(ip))
|
||||
miner = BOSminer(str(ip))
|
||||
elif version == "CGMiner":
|
||||
return CGMiner(str(ip))
|
||||
miner = CGMiner(str(ip))
|
||||
elif version == "BMMiner":
|
||||
return BMMiner(str(ip))
|
||||
return UnknownMiner(str(ip))
|
||||
miner = BMMiner(str(ip))
|
||||
else:
|
||||
miner = UnknownMiner(str(ip))
|
||||
else:
|
||||
miner = UnknownMiner(str(ip))
|
||||
self.miners[ip] = miner
|
||||
return miner
|
||||
|
||||
async def _get_version_data(self, ip: ipaddress.ip_address):
|
||||
@staticmethod
|
||||
async def _get_version_data(ip: ipaddress.ip_address):
|
||||
for i in range(3):
|
||||
try:
|
||||
fut = asyncio.open_connection(str(ip), 4028)
|
||||
# get reader and writer streams
|
||||
reader, writer = await asyncio.open_connection(str(ip), 4028)
|
||||
reader, writer = await asyncio.wait_for(fut, timeout=5)
|
||||
|
||||
# create the command
|
||||
cmd = {"command": "version"}
|
||||
@@ -70,6 +83,11 @@ class MinerFactory:
|
||||
|
||||
# return the data
|
||||
return data
|
||||
except OSError as e:
|
||||
if e.winerror == 121:
|
||||
return None
|
||||
else:
|
||||
print(ip, e)
|
||||
except Exception as e:
|
||||
print(ip, e)
|
||||
return None
|
||||
|
||||
@@ -9,3 +9,6 @@ class UnknownMiner(BaseMiner):
|
||||
|
||||
def __repr__(self):
|
||||
return f"Unknown: {str(self.ip)}"
|
||||
|
||||
async def send_config(self):
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user