set up cgminer get hostname, and fixed the bug with asyncio trying to close non socket objects

This commit is contained in:
UpstreamData
2021-11-09 09:54:31 -07:00
parent 201ba6829a
commit b714dfe4a4
4 changed files with 37 additions and 18 deletions

View File

@@ -9,24 +9,47 @@ class CGMiner(BaseMiner):
super().__init__(ip, api)
self.config = None
self.uname = 'root'
self.pwd = 'root'
self.pwd = 'admin'
def __repr__(self) -> str:
return f"CGMiner: {str(self.ip)}"
async def get_hostname(self) -> str:
return "CGMiner Unknown"
try:
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()
else:
return "CGMiner Unknown"
except Exception as e:
return "CGMiner Unknown"
async def send_config(self):
return None # ignore for now
async def _get_ssh_connection(self) -> asyncssh.connect:
conn = await asyncssh.connect(str(self.ip),
known_hosts=None,
username=self.uname,
password=self.pwd,
server_host_key_algs=['ssh-rsa'])
return conn
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 as e:
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(e)
except OSError:
print(str(self.ip) + " Connection refused.")
return None
async def send_ssh_command(self, cmd):
result = None