moved _get_ssh_connection to the base miner class

This commit is contained in:
UpstreamData
2022-03-16 13:34:18 -06:00
parent bae2ee4245
commit 1be12e5d4c
4 changed files with 33 additions and 76 deletions

View File

@@ -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: