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