added get_model to X19s

This commit is contained in:
UpstreamData
2022-01-07 10:25:29 -07:00
parent 4e8ff9ea74
commit 770b17c86b
5 changed files with 32 additions and 256 deletions

View File

@@ -1,26 +1,18 @@
from API.bmminer import BMMinerAPI
from miners import BaseMiner
from miners.bmminer import BMMiner
class BMMinerX19(BaseMiner):
class BMMinerX19(BMMiner):
def __init__(self, ip: str) -> None:
api = BMMinerAPI(ip)
super().__init__(ip, api)
super().__init__(ip)
def __repr__(self) -> str:
return f"BMMiner: {str(self.ip)}"
return f"BMMinerX19: {str(self.ip)}"
async def get_hostname(self) -> str:
return "BMMiner Unknown"
async def send_config(self, _):
return None # ignore for now
async def restart_backend(self) -> None:
return None # Murray
async def reboot(self) -> None:
return None # Murray
async def get_config(self) -> None:
return None # Murray
async def get_model(self):
if self.model:
return self.model
version_data = await self.api.version()
if version_data:
self.model = version_data["VERSION"][0]["Type"].replace("Antminer ", "")
return self.model
return None

View File

@@ -1,123 +1,19 @@
from miners import BaseMiner
from API.cgminer import CGMinerAPI
import asyncssh
from miners.cgminer import CGMiner
class CGMinerX19(BaseMiner):
class CGMinerX19(CGMiner):
def __init__(self, ip: str) -> None:
api = CGMinerAPI(ip)
super().__init__(ip, api)
self.config = None
self.uname = 'root'
self.pwd = 'admin'
super().__init__(ip)
self.api_type = "CGMiner"
def __repr__(self) -> str:
return f"CGMiner: {str(self.ip)}"
return f"CGMinerX19: {str(self.ip)}"
async def get_hostname(self) -> str:
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:
return "CGMiner Unknown"
async def send_config(self, _):
return None # ignore for now
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(e)
except OSError:
print(str(self.ip) + " Connection refused.")
return None
async def send_ssh_command(self, cmd):
result = None
async with (await self._get_ssh_connection()) as conn:
for i in range(3):
try:
result = await conn.run(cmd)
except Exception as e:
print(f"{cmd} error: {e}")
if i == 3:
return
continue
# handle result
self._result_handler(result)
@staticmethod
def _result_handler(result: asyncssh.process.SSHCompletedProcess) -> None:
if result is not None:
# noinspection PyUnresolvedReferences
if len(result.stdout) > 0:
# noinspection PyUnresolvedReferences
print("ssh stdout: \n" + result.stdout)
# noinspection PyUnresolvedReferences
if len(result.stderr) > 0:
# noinspection PyUnresolvedReferences
print("ssh stderr: \n" + result.stderrr)
# noinspection PyUnresolvedReferences
if len(result.stdout) <= 0 and len(result.stderr) <= 0:
print("ssh stdout stderr empty")
# if result.stdout != "":
# print(result.stdout)
# if result.stderr != "":
# print("ERROR: " + result.stderr)
# elif result.stderr != "":
# print("ERROR: " + result.stderr)
# else:
# print(cmd)
async def restart_cgminer(self) -> None:
commands = ['cgminer-api restart',
'/usr/bin/cgminer-monitor >/dev/null 2>&1']
commands = ';'.join(commands)
await self.send_ssh_command(commands)
async def reboot(self) -> None:
commands = ['reboot']
commands = ';'.join(commands)
await self.send_ssh_command(commands)
async def start_cgminer(self) -> None:
commands = ['mkdir -p /etc/tmp/',
'echo \"*/3 * * * * /usr/bin/cgminer-monitor\" > /etc/tmp/root',
'crontab -u root /etc/tmp/root',
'/usr/bin/cgminer-monitor >/dev/null 2>&1']
commands = ';'.join(commands)
await self.send_ssh_command(commands)
async def stop_cgminer(self) -> None:
commands = ['mkdir -p /etc/tmp/',
'echo \"\" > /etc/tmp/root',
'crontab -u root /etc/tmp/root',
'killall cgminer']
commands = ';'.join(commands)
await self.send_ssh_command(commands)
async def get_config(self) -> None:
async with (await self._get_ssh_connection()) as conn:
command = 'cat /etc/config/cgminer'
result = await conn.run(command, check=True)
self._result_handler(result)
self.config = result.stdout
print(str(self.config))
async def get_model(self):
if self.model:
return self.model
version_data = await self.api.version()
if version_data:
self.model = version_data["VERSION"][0]["Type"].replace("Antminer ", "")
return self.model
return None