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.btminer import BTMinerAPI
|
||||||
from API.unknown import UnknownAPI
|
from API.unknown import UnknownAPI
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
import asyncssh
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class BaseMiner:
|
class BaseMiner:
|
||||||
def __init__(self, ip: str, api: BMMinerAPI | BOSMinerAPI | CGMinerAPI | BTMinerAPI | UnknownAPI) -> None:
|
def __init__(self, ip: str, api: BMMinerAPI | BOSMinerAPI | CGMinerAPI | BTMinerAPI | UnknownAPI) -> None:
|
||||||
self.ip = ipaddress.ip_address(ip)
|
self.ip = ipaddress.ip_address(ip)
|
||||||
|
self.uname = None
|
||||||
|
self.pwd = None
|
||||||
self.api = api
|
self.api = api
|
||||||
self.api_type = None
|
self.api_type = None
|
||||||
self.model = 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):
|
async def get_board_info(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -33,7 +64,3 @@ class BaseMiner:
|
|||||||
|
|
||||||
async def send_config(self, yaml_config):
|
async def send_config(self, yaml_config):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from API.bmminer import BMMinerAPI
|
from API.bmminer import BMMinerAPI
|
||||||
from miners import BaseMiner
|
from miners import BaseMiner
|
||||||
import asyncssh
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
@@ -43,32 +42,6 @@ class BMMiner(BaseMiner):
|
|||||||
logging.warning(f"Failed to get hostname for miner: {self}")
|
logging.warning(f"Failed to get hostname for miner: {self}")
|
||||||
return "?"
|
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):
|
async def send_ssh_command(self, cmd):
|
||||||
result = None
|
result = None
|
||||||
async with (await self._get_ssh_connection()) as conn:
|
async with (await self._get_ssh_connection()) as conn:
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from miners import BaseMiner
|
from miners import BaseMiner
|
||||||
from API.bosminer import BOSMinerAPI
|
from API.bosminer import BOSMinerAPI
|
||||||
import asyncssh
|
|
||||||
import toml
|
import toml
|
||||||
from config.bos import bos_config_convert, general_config_convert_bos
|
from config.bos import bos_config_convert, general_config_convert_bos
|
||||||
import logging
|
import logging
|
||||||
@@ -18,20 +17,6 @@ class BOSMiner(BaseMiner):
|
|||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"BOSminer: {str(self.ip)}"
|
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):
|
async def send_ssh_command(self, cmd: str):
|
||||||
"""Sends SSH command to miner."""
|
"""Sends SSH command to miner."""
|
||||||
# creates result variable
|
# creates result variable
|
||||||
@@ -51,7 +36,6 @@ class BOSMiner(BaseMiner):
|
|||||||
continue
|
continue
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def fault_light_on(self) -> None:
|
async def fault_light_on(self) -> None:
|
||||||
"""Sends command to turn on fault light on the miner."""
|
"""Sends command to turn on fault light on the miner."""
|
||||||
logging.debug(f"{self}: Sending fault_light on command.")
|
logging.debug(f"{self}: Sending fault_light on command.")
|
||||||
@@ -170,7 +154,6 @@ class BOSMiner(BaseMiner):
|
|||||||
bad_boards[board].append(chain)
|
bad_boards[board].append(chain)
|
||||||
return bad_boards
|
return bad_boards
|
||||||
|
|
||||||
|
|
||||||
async def check_good_boards(self) -> str:
|
async def check_good_boards(self) -> str:
|
||||||
"""Checks for and provides list for working boards."""
|
"""Checks for and provides list for working boards."""
|
||||||
devs = await self.api.devdetails()
|
devs = await self.api.devdetails()
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from miners import BaseMiner
|
from miners import BaseMiner
|
||||||
from API.cgminer import CGMinerAPI
|
from API.cgminer import CGMinerAPI
|
||||||
from API import APIError
|
from API import APIError
|
||||||
import asyncssh
|
|
||||||
|
|
||||||
|
|
||||||
class CGMiner(BaseMiner):
|
class CGMiner(BaseMiner):
|
||||||
@@ -24,7 +23,8 @@ class CGMiner(BaseMiner):
|
|||||||
except APIError:
|
except APIError:
|
||||||
return None
|
return None
|
||||||
if version_data:
|
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 self.model
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -39,32 +39,6 @@ class CGMiner(BaseMiner):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return "?"
|
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):
|
async def send_ssh_command(self, cmd):
|
||||||
result = None
|
result = None
|
||||||
async with (await self._get_ssh_connection()) as conn:
|
async with (await self._get_ssh_connection()) as conn:
|
||||||
|
|||||||
Reference in New Issue
Block a user