fixed a bug with suspended whatsminers
This commit is contained in:
@@ -7,6 +7,7 @@ from settings import MINER_FACTORY_GET_VERSION_RETRIES as DATA_RETRIES
|
|||||||
class BMMiner(BaseMiner):
|
class BMMiner(BaseMiner):
|
||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
|
self.ip = ip
|
||||||
self.api = BMMinerAPI(ip)
|
self.api = BMMinerAPI(ip)
|
||||||
self.api_type = "BMMiner"
|
self.api_type = "BMMiner"
|
||||||
self.uname = "root"
|
self.uname = "root"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import asyncssh
|
|||||||
class BOSMiner(BaseMiner):
|
class BOSMiner(BaseMiner):
|
||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
|
self.ip = ip
|
||||||
self.api = BOSMinerAPI(ip)
|
self.api = BOSMinerAPI(ip)
|
||||||
self.api_type = "BOSMiner"
|
self.api_type = "BOSMiner"
|
||||||
self.uname = "root"
|
self.uname = "root"
|
||||||
@@ -379,7 +380,6 @@ class BOSMinerOld(BaseMiner):
|
|||||||
self.uname = "root"
|
self.uname = "root"
|
||||||
self.pwd = "admin"
|
self.pwd = "admin"
|
||||||
|
|
||||||
|
|
||||||
async def send_ssh_command(self, cmd: str) -> str or None:
|
async def send_ssh_command(self, cmd: str) -> str or None:
|
||||||
"""Send a command to the miner over ssh.
|
"""Send a command to the miner over ssh.
|
||||||
|
|
||||||
@@ -406,9 +406,6 @@ class BOSMinerOld(BaseMiner):
|
|||||||
# return the result, either command output or None
|
# return the result, either command output or None
|
||||||
return str(result)
|
return str(result)
|
||||||
|
|
||||||
|
|
||||||
async def update_to_plus(self):
|
async def update_to_plus(self):
|
||||||
result = await self.send_ssh_command("opkg update && opkg install bos_plus")
|
result = await self.send_ssh_command("opkg update && opkg install bos_plus")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from settings import MINER_FACTORY_GET_VERSION_RETRIES as DATA_RETRIES
|
|||||||
class BTMiner(BaseMiner):
|
class BTMiner(BaseMiner):
|
||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
|
self.ip = ip
|
||||||
self.api = BTMinerAPI(ip)
|
self.api = BTMinerAPI(ip)
|
||||||
self.api_type = "BTMiner"
|
self.api_type = "BTMiner"
|
||||||
|
|
||||||
@@ -93,8 +94,15 @@ class BTMiner(BaseMiner):
|
|||||||
"Pool 2 User": "",
|
"Pool 2 User": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
model = await self.get_model()
|
try:
|
||||||
hostname = await self.get_hostname()
|
model = await self.get_model()
|
||||||
|
hostname = await self.get_hostname()
|
||||||
|
except APIError:
|
||||||
|
logging.warning(f"Failed to get hostname and model: {self}")
|
||||||
|
model = None
|
||||||
|
data["Model"] = "Whatsminer"
|
||||||
|
hostname = None
|
||||||
|
data["Hostname"] = "Whatsminer"
|
||||||
|
|
||||||
if model:
|
if model:
|
||||||
data["Model"] = model
|
data["Model"] = model
|
||||||
@@ -103,9 +111,12 @@ class BTMiner(BaseMiner):
|
|||||||
data["Hostname"] = hostname
|
data["Hostname"] = hostname
|
||||||
miner_data = None
|
miner_data = None
|
||||||
for i in range(DATA_RETRIES):
|
for i in range(DATA_RETRIES):
|
||||||
miner_data = await self.api.multicommand("summary", "devs", "pools")
|
try:
|
||||||
if miner_data:
|
miner_data = await self.api.multicommand("summary", "devs", "pools")
|
||||||
break
|
if miner_data:
|
||||||
|
break
|
||||||
|
except APIError:
|
||||||
|
pass
|
||||||
|
|
||||||
if not miner_data:
|
if not miner_data:
|
||||||
return data
|
return data
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import logging
|
|||||||
class CGMiner(BaseMiner):
|
class CGMiner(BaseMiner):
|
||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
|
self.ip = ip
|
||||||
self.api = CGMinerAPI(ip)
|
self.api = CGMinerAPI(ip)
|
||||||
self.api_type = "CGMiner"
|
self.api_type = "CGMiner"
|
||||||
self.uname = "root"
|
self.uname = "root"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from miners._backends import BMMiner
|
|||||||
class Hiveon(BMMiner):
|
class Hiveon(BMMiner):
|
||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
|
self.ip = ip
|
||||||
self.api_type = "Hiveon"
|
self.api_type = "Hiveon"
|
||||||
self.uname = "root"
|
self.uname = "root"
|
||||||
self.pwd = "admin"
|
self.pwd = "admin"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from miners.avalonminer import *
|
|||||||
from miners._backends.cgminer import CGMiner
|
from miners._backends.cgminer import CGMiner
|
||||||
from miners._backends.bmminer import BMMiner
|
from miners._backends.bmminer import BMMiner
|
||||||
from miners._backends.bosminer import BOSMiner
|
from miners._backends.bosminer import BOSMiner
|
||||||
|
from miners._backends.btminer import BTMiner
|
||||||
from miners._backends.bosminer import BOSMinerOld
|
from miners._backends.bosminer import BOSMinerOld
|
||||||
|
|
||||||
from miners.unknown import UnknownMiner
|
from miners.unknown import UnknownMiner
|
||||||
@@ -245,10 +246,13 @@ class MinerFactory(metaclass=Singleton):
|
|||||||
if api:
|
if api:
|
||||||
if "BOSMiner+" in api:
|
if "BOSMiner+" in api:
|
||||||
miner = BOSMiner(str(ip))
|
miner = BOSMiner(str(ip))
|
||||||
if "BOSMiner" in api:
|
elif "BOSMiner" in api:
|
||||||
miner = BOSMinerOld(str(ip))
|
miner = BOSMinerOld(str(ip))
|
||||||
elif "CGMiner" in api:
|
elif "CGMiner" in api:
|
||||||
miner = CGMiner(str(ip))
|
miner = CGMiner(str(ip))
|
||||||
|
elif "BTMiner" in api:
|
||||||
|
miner = BTMiner(str(ip))
|
||||||
|
print(miner)
|
||||||
elif "BMMiner" in api:
|
elif "BMMiner" in api:
|
||||||
miner = BMMiner(str(ip))
|
miner = BMMiner(str(ip))
|
||||||
|
|
||||||
@@ -288,11 +292,15 @@ class MinerFactory(metaclass=Singleton):
|
|||||||
devdetails = await self._send_api_command(str(ip), "devdetails")
|
devdetails = await self._send_api_command(str(ip), "devdetails")
|
||||||
validation = await self._validate_command(devdetails)
|
validation = await self._validate_command(devdetails)
|
||||||
if not validation[0]:
|
if not validation[0]:
|
||||||
|
devdetails = None
|
||||||
version = await self._send_api_command(str(ip), "version")
|
version = await self._send_api_command(str(ip), "version")
|
||||||
|
|
||||||
validation = await self._validate_command(version)
|
validation = await self._validate_command(version)
|
||||||
if not validation[0]:
|
if not validation[0]:
|
||||||
raise APIError(validation[1])
|
version = await self._send_api_command(str(ip), "get_version")
|
||||||
|
|
||||||
|
validation = await self._validate_command(version)
|
||||||
|
if not validation[0]:
|
||||||
|
raise APIError(validation[1])
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
logging.warning(f"{ip}: API Command Error: {e}")
|
logging.warning(f"{ip}: API Command Error: {e}")
|
||||||
return None, None
|
return None, None
|
||||||
@@ -313,22 +321,29 @@ class MinerFactory(metaclass=Singleton):
|
|||||||
model = "Antminer S9"
|
model = "Antminer S9"
|
||||||
|
|
||||||
if version:
|
if version:
|
||||||
# check if there are any BMMiner strings in any of the dict keys
|
if "VERSION" in version.keys():
|
||||||
if any("BMMiner" in string for string in version["VERSION"][0].keys()):
|
# check if there are any BMMiner strings in any of the dict keys
|
||||||
api = "BMMiner"
|
if any("BMMiner" in string for string in version["VERSION"][0].keys()):
|
||||||
|
api = "BMMiner"
|
||||||
|
|
||||||
# check if there are any CGMiner strings in any of the dict keys
|
# check if there are any CGMiner strings in any of the dict keys
|
||||||
elif any("CGMiner" in string for string in version["VERSION"][0].keys()):
|
elif any(
|
||||||
api = "CGMiner"
|
"CGMiner" in string for string in version["VERSION"][0].keys()
|
||||||
|
):
|
||||||
|
api = "CGMiner"
|
||||||
|
|
||||||
# check if there are any BOSMiner strings in any of the dict keys
|
# check if there are any BOSMiner strings in any of the dict keys
|
||||||
elif any("BOSminer" in string for string in version["VERSION"][0].keys()):
|
elif any(
|
||||||
api = "BOSMiner"
|
"BOSminer" in string for string in version["VERSION"][0].keys()
|
||||||
if "plus" in version["VERSION"][0]["BOSminer"]:
|
):
|
||||||
api = "BOSMiner+"
|
api = "BOSMiner"
|
||||||
|
if "plus" in version["VERSION"][0]["BOSminer"]:
|
||||||
|
api = "BOSMiner+"
|
||||||
|
|
||||||
# if all that fails, check the Description to see if it is a whatsminer
|
# if all that fails, check the Description to see if it is a whatsminer
|
||||||
if version.get("Description") and "whatsminer" in version.get("Description"):
|
if version.get("Description") and "whatsminer" in version.get(
|
||||||
|
"Description"
|
||||||
|
):
|
||||||
api = "BTMiner"
|
api = "BTMiner"
|
||||||
if version and not model:
|
if version and not model:
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user