added logging to bmminer and X19 models

This commit is contained in:
UpstreamData
2022-03-14 16:07:47 -06:00
parent c22be7ded8
commit 07a8b00a93
4 changed files with 24 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
from miners.bmminer import BMMiner
import logging
class BMMinerX19(BMMiner):
@@ -10,9 +11,12 @@ class BMMinerX19(BMMiner):
async def get_model(self):
if self.model:
logging.debug(f"Found model for {self.ip}: {self.model}")
return self.model
version_data = await self.api.version()
if version_data:
self.model = version_data["VERSION"][0]["Type"].replace("Antminer ", "")
logging.debug(f"Found model for {self.ip}: {self.model}")
return self.model
logging.warning(f"Failed to get model for miner: {self}")
return None

View File

@@ -1,4 +1,5 @@
from miners.cgminer import CGMiner
import logging
class CGMinerX19(CGMiner):
@@ -11,9 +12,12 @@ class CGMinerX19(CGMiner):
async def get_model(self):
if self.model:
logging.debug(f"Found model for {self.ip}: {self.model}")
return self.model
version_data = await self.api.version()
if version_data:
self.model = version_data["VERSION"][0]["Type"].replace("Antminer ", "")
logging.debug(f"Found model for {self.ip}: {self.model}")
return self.model
logging.warning(f"Failed to get model for miner: {self}")
return None

View File

@@ -1,6 +1,7 @@
from API.bmminer import BMMinerAPI
from miners import BaseMiner
import asyncssh
import logging
class BMMiner(BaseMiner):
@@ -17,11 +18,14 @@ class BMMiner(BaseMiner):
async def get_model(self):
if self.model:
logging.debug(f"Found model for {self.ip}: {self.model}")
return self.model
version_data = await self.api.devdetails()
if version_data:
self.model = version_data["DEVDETAILS"][0]["Model"].replace("Antminer ", "")
logging.debug(f"Found model for {self.ip}: {self.model}")
return self.model
logging.warning(f"Failed to get model for miner: {self}")
return None
async def get_hostname(self) -> str:
@@ -29,10 +33,14 @@ class BMMiner(BaseMiner):
async with (await self._get_ssh_connection()) as conn:
if conn is not None:
data = await conn.run('cat /proc/sys/kernel/hostname')
return data.stdout.strip()
host = data.stdout.strip()
logging.debug(f"Found hostname for {self.ip}: {host}")
return host
else:
logging.warning(f"Failed to get hostname for miner: {self}")
return "?"
except Exception:
logging.warning(f"Failed to get hostname for miner: {self}")
return "?"
async def _get_ssh_connection(self) -> asyncssh.connect:
@@ -52,16 +60,15 @@ class BMMiner(BaseMiner):
server_host_key_algs=['ssh-rsa'])
return conn
except Exception as e:
print("Exception raised:", self.ip)
logging.warning(f"{self} raised an exception: {e}")
raise e
except OSError:
print(str(self.ip) + ": Connection refused.")
logging.warning(f"Connection refused: {self} ")
return None
except Exception as e:
print("Exception raised:", self.ip)
logging.warning(f"{self} raised an exception: {e}")
raise e
async def send_ssh_command(self, cmd):
result = None
async with (await self._get_ssh_connection()) as conn:
@@ -69,11 +76,12 @@ class BMMiner(BaseMiner):
try:
result = await conn.run(cmd)
except Exception as e:
print(f"{cmd} error: {e}")
logging.warning(f"{self} command {cmd} error: {e}")
if i == 3:
return
continue
return result
async def reboot(self) -> None:
logging.debug(f"{self}: Sending reboot command.")
await self.send_ssh_command("reboot")