moved _get_ssh_connection to the base miner class
This commit is contained in:
@@ -4,15 +4,46 @@ from API.cgminer import CGMinerAPI
|
||||
from API.btminer import BTMinerAPI
|
||||
from API.unknown import UnknownAPI
|
||||
import ipaddress
|
||||
import asyncssh
|
||||
import logging
|
||||
|
||||
|
||||
class BaseMiner:
|
||||
def __init__(self, ip: str, api: BMMinerAPI | BOSMinerAPI | CGMinerAPI | BTMinerAPI | UnknownAPI) -> None:
|
||||
self.ip = ipaddress.ip_address(ip)
|
||||
self.uname = None
|
||||
self.pwd = None
|
||||
self.api = api
|
||||
self.api_type = None
|
||||
self.model = None
|
||||
|
||||
async def _get_ssh_connection(self) -> asyncssh.connect:
|
||||
"""Create a new asyncssh connection"""
|
||||
try:
|
||||
conn = await asyncssh.connect(str(self.ip),
|
||||
known_hosts=None,
|
||||
username=self.uname,
|
||||
password=self.pwd,
|
||||
server_host_key_algs=['ssh-rsa'])
|
||||
return conn
|
||||
except asyncssh.misc.PermissionDenied:
|
||||
try:
|
||||
conn = await asyncssh.connect(str(self.ip),
|
||||
known_hosts=None,
|
||||
username="admin",
|
||||
password="admin",
|
||||
server_host_key_algs=['ssh-rsa'])
|
||||
return conn
|
||||
except Exception as e:
|
||||
logging.warning(f"{self} raised an exception: {e}")
|
||||
raise e
|
||||
except OSError:
|
||||
logging.warning(f"Connection refused: {self}")
|
||||
return None
|
||||
except Exception as e:
|
||||
logging.warning(f"{self} raised an exception: {e}")
|
||||
raise e
|
||||
|
||||
async def get_board_info(self):
|
||||
return None
|
||||
|
||||
@@ -33,7 +64,3 @@ class BaseMiner:
|
||||
|
||||
async def send_config(self, yaml_config):
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from API.bmminer import BMMinerAPI
|
||||
from miners import BaseMiner
|
||||
import asyncssh
|
||||
import logging
|
||||
|
||||
|
||||
@@ -43,32 +42,6 @@ class BMMiner(BaseMiner):
|
||||
logging.warning(f"Failed to get hostname for miner: {self}")
|
||||
return "?"
|
||||
|
||||
async def _get_ssh_connection(self) -> asyncssh.connect:
|
||||
try:
|
||||
conn = await asyncssh.connect(str(self.ip),
|
||||
known_hosts=None,
|
||||
username=self.uname,
|
||||
password=self.pwd,
|
||||
server_host_key_algs=['ssh-rsa'])
|
||||
return conn
|
||||
except asyncssh.misc.PermissionDenied:
|
||||
try:
|
||||
conn = await asyncssh.connect(str(self.ip),
|
||||
known_hosts=None,
|
||||
username="admin",
|
||||
password="admin",
|
||||
server_host_key_algs=['ssh-rsa'])
|
||||
return conn
|
||||
except Exception as e:
|
||||
logging.warning(f"{self} raised an exception: {e}")
|
||||
raise e
|
||||
except OSError:
|
||||
logging.warning(f"Connection refused: {self} ")
|
||||
return None
|
||||
except Exception as e:
|
||||
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:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from miners import BaseMiner
|
||||
from API.bosminer import BOSMinerAPI
|
||||
import asyncssh
|
||||
import toml
|
||||
from config.bos import bos_config_convert, general_config_convert_bos
|
||||
import logging
|
||||
@@ -18,20 +17,6 @@ class BOSMiner(BaseMiner):
|
||||
def __repr__(self) -> str:
|
||||
return f"BOSminer: {str(self.ip)}"
|
||||
|
||||
async def _get_ssh_connection(self) -> asyncssh.connect:
|
||||
"""Create a new asyncssh connection"""
|
||||
try:
|
||||
conn = await asyncssh.connect(str(self.ip), known_hosts=None, username=self.uname, password=self.pwd,
|
||||
server_host_key_algs=['ssh-rsa'])
|
||||
except OSError:
|
||||
logging.warning(f"Connection refused: {self} ")
|
||||
return None
|
||||
except Exception as e:
|
||||
logging.warning(f"{self} raised an exception: {e}")
|
||||
raise e
|
||||
# return created connection
|
||||
return conn
|
||||
|
||||
async def send_ssh_command(self, cmd: str):
|
||||
"""Sends SSH command to miner."""
|
||||
# creates result variable
|
||||
@@ -51,7 +36,6 @@ class BOSMiner(BaseMiner):
|
||||
continue
|
||||
return result
|
||||
|
||||
|
||||
async def fault_light_on(self) -> None:
|
||||
"""Sends command to turn on fault light on the miner."""
|
||||
logging.debug(f"{self}: Sending fault_light on command.")
|
||||
@@ -170,7 +154,6 @@ class BOSMiner(BaseMiner):
|
||||
bad_boards[board].append(chain)
|
||||
return bad_boards
|
||||
|
||||
|
||||
async def check_good_boards(self) -> str:
|
||||
"""Checks for and provides list for working boards."""
|
||||
devs = await self.api.devdetails()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from miners import BaseMiner
|
||||
from API.cgminer import CGMinerAPI
|
||||
from API import APIError
|
||||
import asyncssh
|
||||
|
||||
|
||||
class CGMiner(BaseMiner):
|
||||
@@ -24,7 +23,8 @@ class CGMiner(BaseMiner):
|
||||
except APIError:
|
||||
return None
|
||||
if version_data:
|
||||
self.model = version_data["DEVDETAILS"][0]["Model"].replace("Antminer ", "")
|
||||
self.model = version_data["DEVDETAILS"][0]["Model"].replace(
|
||||
"Antminer ", "")
|
||||
return self.model
|
||||
return None
|
||||
|
||||
@@ -39,32 +39,6 @@ class CGMiner(BaseMiner):
|
||||
except Exception:
|
||||
return "?"
|
||||
|
||||
async def _get_ssh_connection(self) -> asyncssh.connect:
|
||||
try:
|
||||
conn = await asyncssh.connect(str(self.ip),
|
||||
known_hosts=None,
|
||||
username=self.uname,
|
||||
password=self.pwd,
|
||||
server_host_key_algs=['ssh-rsa'])
|
||||
return conn
|
||||
except asyncssh.misc.PermissionDenied:
|
||||
try:
|
||||
conn = await asyncssh.connect(str(self.ip),
|
||||
known_hosts=None,
|
||||
username="admin",
|
||||
password="admin",
|
||||
server_host_key_algs=['ssh-rsa'])
|
||||
return conn
|
||||
except Exception as e:
|
||||
print("Exception raised:", self.ip)
|
||||
raise e
|
||||
except OSError:
|
||||
print(str(self.ip) + " Connection refused.")
|
||||
return None
|
||||
except Exception as e:
|
||||
print("Exception raised:", self.ip)
|
||||
raise e
|
||||
|
||||
async def send_ssh_command(self, cmd):
|
||||
result = None
|
||||
async with (await self._get_ssh_connection()) as conn:
|
||||
|
||||
Reference in New Issue
Block a user