* changed over to package format and removed tools, added poetry * reformat into miner_interface project * add dist to .gitignore * update readme and finish reformatting * Added couple missing imports. (#13) * change name to pyasic Co-authored-by: upstreamdata <brett@upstreamdata.ca> Co-authored-by: Mika Impola <mika@impola.fi>
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import logging
|
|
|
|
import ipaddress
|
|
|
|
from pyasic.API.bosminer import BOSMinerAPI
|
|
from pyasic.miners import BaseMiner
|
|
|
|
|
|
class BOSMinerOld(BaseMiner):
|
|
def __init__(self, ip: str) -> None:
|
|
super().__init__(ip)
|
|
self.ip = ipaddress.ip_address(ip)
|
|
self.api = BOSMinerAPI(ip)
|
|
self.api_type = "BOSMiner"
|
|
self.uname = "root"
|
|
self.pwd = "admin"
|
|
|
|
async def send_ssh_command(self, cmd: str) -> str or None:
|
|
"""Send a command to the miner over ssh.
|
|
|
|
:return: Result of the command or None.
|
|
"""
|
|
result = None
|
|
|
|
# open an ssh connection
|
|
async with (await self._get_ssh_connection()) as conn:
|
|
# 3 retries
|
|
for i in range(3):
|
|
try:
|
|
# run the command and get the result
|
|
result = await conn.run(cmd)
|
|
if result.stdout:
|
|
result = result.stdout
|
|
except Exception as e:
|
|
if e == "SSH connection closed":
|
|
return "Update completed."
|
|
# if the command fails, log it
|
|
logging.warning(f"{self} command {cmd} error: {e}")
|
|
|
|
# on the 3rd retry, return None
|
|
if i == 3:
|
|
return
|
|
continue
|
|
# return the result, either command output or None
|
|
return str(result)
|
|
|
|
|
|
async def update_to_plus(self):
|
|
result = await self.send_ssh_command("opkg update && opkg install bos_plus")
|
|
return result
|