From 4a2adabe9505085602170fb475c2f78c93d9b634 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Fri, 7 Jun 2024 02:04:16 +0530 Subject: [PATCH 01/13] feat: Add update firmware for Auradine and ePIC miners --- pyasic/miners/backends/auradine.py | 52 +++++++++++++++++++++++++++++ pyasic/miners/backends/bfgminer.py | 2 ++ pyasic/miners/backends/epic.py | 53 ++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) diff --git a/pyasic/miners/backends/auradine.py b/pyasic/miners/backends/auradine.py index 37290048..d29cb2f6 100644 --- a/pyasic/miners/backends/auradine.py +++ b/pyasic/miners/backends/auradine.py @@ -16,6 +16,9 @@ import logging from enum import Enum from typing import List, Optional +import aiofiles +import base64 +from pathlib import Path from pyasic.config import MinerConfig from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit @@ -386,3 +389,52 @@ class Auradine(StockFirmware): return rpc_summary["SUMMARY"][0]["Elapsed"] except LookupError: pass + + async def upgrade_firmware(self, file: Path): + """ + Upgrade the firmware of the Auradine miner device. + + Args: + file (Path): The local file path of the firmware to be uploaded. + + Returns: + str: Confirmation message after upgrading the firmware. + """ + try: + logging.info("Starting firmware upgrade process for Auradine miner.") + + if not file: + raise ValueError("File location must be provided for firmware upgrade.") + + # Read the firmware file contents + async with aiofiles.open(file, "rb") as f: + upgrade_contents = await f.read() + + # Encode the firmware contents in base64 + encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") + + # Upload the firmware file to the Auradine miner device + logging.info(f"Uploading firmware file from {file} to the device.") + await self.ssh.send_command( + f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" + ) + + logging.info("Firmware upgrade process completed successfully for Auradine miner.") + return "Firmware upgrade completed successfully." + except FileNotFoundError as e: + logging.error(f"File not found during the firmware upgrade process: {e}") + raise + except ValueError as e: + logging.error( + f"Validation error occurred during the firmware upgrade process: {e}" + ) + raise + except OSError as e: + logging.error(f"OS error occurred during the firmware upgrade process: {e}") + raise + except Exception as e: + logging.error( + f"An unexpected error occurred during the firmware upgrade process: {e}", + exc_info=True, + ) + raise diff --git a/pyasic/miners/backends/bfgminer.py b/pyasic/miners/backends/bfgminer.py index e2b3cdea..c45231f1 100644 --- a/pyasic/miners/backends/bfgminer.py +++ b/pyasic/miners/backends/bfgminer.py @@ -227,3 +227,5 @@ class BFGMiner(StockFirmware): ).into(self.algo.unit.default) except LookupError: pass + + diff --git a/pyasic/miners/backends/epic.py b/pyasic/miners/backends/epic.py index e3134dfc..49b45909 100644 --- a/pyasic/miners/backends/epic.py +++ b/pyasic/miners/backends/epic.py @@ -15,6 +15,10 @@ # ------------------------------------------------------------------------------ from typing import List, Optional +import logging +import aiofiles +import base64 +from pathlib import Path from pyasic.config import MinerConfig from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit @@ -411,3 +415,52 @@ class ePIC(ePICFirmware): except KeyError: pass return errors + + async def upgrade_firmware(self, file: Path): + """ + Upgrade the firmware of the ePIC miner device. + + Args: + file (Path): The local file path of the firmware to be uploaded. + + Returns: + str: Confirmation message after upgrading the firmware. + """ + try: + logging.info("Starting firmware upgrade process for ePIC miner.") + + if not file: + raise ValueError("File location must be provided for firmware upgrade.") + + # Read the firmware file contents + async with aiofiles.open(file, "rb") as f: + upgrade_contents = await f.read() + + # Encode the firmware contents in base64 + encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") + + # Upload the firmware file to the ePIC miner device + logging.info(f"Uploading firmware file from {file} to the device.") + await self.ssh.send_command( + f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" + ) + + logging.info("Firmware upgrade process completed successfully for ePIC miner.") + return "Firmware upgrade completed successfully." + except FileNotFoundError as e: + logging.error(f"File not found during the firmware upgrade process: {e}") + raise + except ValueError as e: + logging.error( + f"Validation error occurred during the firmware upgrade process: {e}" + ) + raise + except OSError as e: + logging.error(f"OS error occurred during the firmware upgrade process: {e}") + raise + except Exception as e: + logging.error( + f"An unexpected error occurred during the firmware upgrade process: {e}", + exc_info=True, + ) + raise \ No newline at end of file From bf0e2e6cfe7158c4967d0f73796d974d57a41618 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Fri, 7 Jun 2024 02:12:48 +0530 Subject: [PATCH 02/13] feat: Add update firmware for BFG miner --- pyasic/miners/backends/bfgminer.py | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pyasic/miners/backends/bfgminer.py b/pyasic/miners/backends/bfgminer.py index c45231f1..cc22caf9 100644 --- a/pyasic/miners/backends/bfgminer.py +++ b/pyasic/miners/backends/bfgminer.py @@ -15,6 +15,10 @@ # ------------------------------------------------------------------------------ from typing import List, Optional +import logging +import aiofiles +import base64 +from pathlib import Path from pyasic.config import MinerConfig from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit @@ -228,4 +232,51 @@ class BFGMiner(StockFirmware): except LookupError: pass + async def upgrade_firmware(self, file: Path): + """ + Upgrade the firmware of the BFG miner device. + Args: + file (Path): The local file path of the firmware to be uploaded. + + Returns: + str: Confirmation message after upgrading the firmware. + """ + try: + logging.info("Starting firmware upgrade process for BFG miner.") + + if not file: + raise ValueError("File location must be provided for firmware upgrade.") + + # Read the firmware file contents + async with aiofiles.open(file, "rb") as f: + upgrade_contents = await f.read() + + # Encode the firmware contents in base64 + encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") + + # Upload the firmware file to the BFG miner device + logging.info(f"Uploading firmware file from {file} to the device.") + await self.ssh.send_command( + f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" + ) + + logging.info("Firmware upgrade process completed successfully for BFG miner.") + return "Firmware upgrade completed successfully." + except FileNotFoundError as e: + logging.error(f"File not found during the firmware upgrade process: {e}") + raise + except ValueError as e: + logging.error( + f"Validation error occurred during the firmware upgrade process: {e}" + ) + raise + except OSError as e: + logging.error(f"OS error occurred during the firmware upgrade process: {e}") + raise + except Exception as e: + logging.error( + f"An unexpected error occurred during the firmware upgrade process: {e}", + exc_info=True, + ) + raise \ No newline at end of file From 9c41a6b28fff8b29bbcf77a4c13690d0897107ce Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Fri, 7 Jun 2024 02:21:41 +0530 Subject: [PATCH 03/13] Undo changes for ePIC and BFG miners --- pyasic/miners/backends/bfgminer.py | 55 +----------------------------- pyasic/miners/backends/epic.py | 55 +----------------------------- 2 files changed, 2 insertions(+), 108 deletions(-) diff --git a/pyasic/miners/backends/bfgminer.py b/pyasic/miners/backends/bfgminer.py index cc22caf9..5b1a3b8c 100644 --- a/pyasic/miners/backends/bfgminer.py +++ b/pyasic/miners/backends/bfgminer.py @@ -15,10 +15,6 @@ # ------------------------------------------------------------------------------ from typing import List, Optional -import logging -import aiofiles -import base64 -from pathlib import Path from pyasic.config import MinerConfig from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit @@ -230,53 +226,4 @@ class BFGMiner(StockFirmware): expected_rate, HashUnit.SHA256.from_str(rate_unit) ).into(self.algo.unit.default) except LookupError: - pass - - async def upgrade_firmware(self, file: Path): - """ - Upgrade the firmware of the BFG miner device. - - Args: - file (Path): The local file path of the firmware to be uploaded. - - Returns: - str: Confirmation message after upgrading the firmware. - """ - try: - logging.info("Starting firmware upgrade process for BFG miner.") - - if not file: - raise ValueError("File location must be provided for firmware upgrade.") - - # Read the firmware file contents - async with aiofiles.open(file, "rb") as f: - upgrade_contents = await f.read() - - # Encode the firmware contents in base64 - encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") - - # Upload the firmware file to the BFG miner device - logging.info(f"Uploading firmware file from {file} to the device.") - await self.ssh.send_command( - f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" - ) - - logging.info("Firmware upgrade process completed successfully for BFG miner.") - return "Firmware upgrade completed successfully." - except FileNotFoundError as e: - logging.error(f"File not found during the firmware upgrade process: {e}") - raise - except ValueError as e: - logging.error( - f"Validation error occurred during the firmware upgrade process: {e}" - ) - raise - except OSError as e: - logging.error(f"OS error occurred during the firmware upgrade process: {e}") - raise - except Exception as e: - logging.error( - f"An unexpected error occurred during the firmware upgrade process: {e}", - exc_info=True, - ) - raise \ No newline at end of file + pass \ No newline at end of file diff --git a/pyasic/miners/backends/epic.py b/pyasic/miners/backends/epic.py index 49b45909..53bdc1a4 100644 --- a/pyasic/miners/backends/epic.py +++ b/pyasic/miners/backends/epic.py @@ -15,10 +15,6 @@ # ------------------------------------------------------------------------------ from typing import List, Optional -import logging -import aiofiles -import base64 -from pathlib import Path from pyasic.config import MinerConfig from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit @@ -414,53 +410,4 @@ class ePIC(ePICFirmware): return errors except KeyError: pass - return errors - - async def upgrade_firmware(self, file: Path): - """ - Upgrade the firmware of the ePIC miner device. - - Args: - file (Path): The local file path of the firmware to be uploaded. - - Returns: - str: Confirmation message after upgrading the firmware. - """ - try: - logging.info("Starting firmware upgrade process for ePIC miner.") - - if not file: - raise ValueError("File location must be provided for firmware upgrade.") - - # Read the firmware file contents - async with aiofiles.open(file, "rb") as f: - upgrade_contents = await f.read() - - # Encode the firmware contents in base64 - encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") - - # Upload the firmware file to the ePIC miner device - logging.info(f"Uploading firmware file from {file} to the device.") - await self.ssh.send_command( - f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" - ) - - logging.info("Firmware upgrade process completed successfully for ePIC miner.") - return "Firmware upgrade completed successfully." - except FileNotFoundError as e: - logging.error(f"File not found during the firmware upgrade process: {e}") - raise - except ValueError as e: - logging.error( - f"Validation error occurred during the firmware upgrade process: {e}" - ) - raise - except OSError as e: - logging.error(f"OS error occurred during the firmware upgrade process: {e}") - raise - except Exception as e: - logging.error( - f"An unexpected error occurred during the firmware upgrade process: {e}", - exc_info=True, - ) - raise \ No newline at end of file + return errors \ No newline at end of file From eefb055a3f2c67f9eecd250a288a63a1dee31142 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Fri, 7 Jun 2024 02:58:09 +0530 Subject: [PATCH 04/13] Fixed upgrade_firmware for auradine miner --- pyasic/miners/backends/auradine.py | 46 ++++++------------------------ 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/pyasic/miners/backends/auradine.py b/pyasic/miners/backends/auradine.py index d29cb2f6..dd53daad 100644 --- a/pyasic/miners/backends/auradine.py +++ b/pyasic/miners/backends/auradine.py @@ -16,9 +16,6 @@ import logging from enum import Enum from typing import List, Optional -import aiofiles -import base64 -from pathlib import Path from pyasic.config import MinerConfig from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit @@ -390,51 +387,26 @@ class Auradine(StockFirmware): except LookupError: pass - async def upgrade_firmware(self, file: Path): + async def upgrade_firmware(self, url: str = None, version: str = "latest") -> dict: """ - Upgrade the firmware of the Auradine miner device. + Upgrade the firmware of the Auradine miner. Args: - file (Path): The local file path of the firmware to be uploaded. + url (str, optional): The URL to download the firmware from. + version (str, optional): The version of the firmware to upgrade to, defaults to 'latest'. Returns: - str: Confirmation message after upgrading the firmware. + dict: A dictionary indicating the result of the firmware upgrade. """ try: logging.info("Starting firmware upgrade process for Auradine miner.") - if not file: - raise ValueError("File location must be provided for firmware upgrade.") - - # Read the firmware file contents - async with aiofiles.open(file, "rb") as f: - upgrade_contents = await f.read() - - # Encode the firmware contents in base64 - encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") - - # Upload the firmware file to the Auradine miner device - logging.info(f"Uploading firmware file from {file} to the device.") - await self.ssh.send_command( - f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" - ) - - logging.info("Firmware upgrade process completed successfully for Auradine miner.") - return "Firmware upgrade completed successfully." - except FileNotFoundError as e: - logging.error(f"File not found during the firmware upgrade process: {e}") - raise - except ValueError as e: - logging.error( - f"Validation error occurred during the firmware upgrade process: {e}" - ) - raise - except OSError as e: - logging.error(f"OS error occurred during the firmware upgrade process: {e}") - raise + if url is not None: + return await self.web.firmware_upgrade(url=url) + return await self.web.firmware_upgrade(version=version) except Exception as e: logging.error( f"An unexpected error occurred during the firmware upgrade process: {e}", exc_info=True, ) - raise + raise \ No newline at end of file From 999e8ef3188b56f5487e1edd35988e0bfee12832 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Sat, 15 Jun 2024 17:44:20 +0530 Subject: [PATCH 05/13] Made consistent API calls --- pyasic/miners/backends/auradine.py | 64 ++++++++++++++++++------------ pyasic/miners/base.py | 20 ++++++++++ 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/pyasic/miners/backends/auradine.py b/pyasic/miners/backends/auradine.py index dd53daad..e574f4a6 100644 --- a/pyasic/miners/backends/auradine.py +++ b/pyasic/miners/backends/auradine.py @@ -15,6 +15,8 @@ # ------------------------------------------------------------------------------ import logging from enum import Enum +import httpx +import aiofiles from typing import List, Optional from pyasic.config import MinerConfig @@ -193,6 +195,42 @@ class Auradine(StockFirmware): for key in conf.keys(): await self.web.send_command(command=key, **conf[key]) + async def upgrade_firmware(self, url: str = None, file_path: str = None, version: str = "latest") -> bool: + """ + Upgrade the firmware of the Auradine device. + + Args: + url (str): The URL to download the firmware from. + file_path (str): The local file path of the firmware to be uploaded. + version (str): The version of the firmware to upgrade to. + + Returns: + bool: True if the firmware upgrade was successful, False otherwise. + """ + try: + logging.info("Starting firmware upgrade process.") + + if not url and not file_path: + raise ValueError("Either URL or file path must be provided for firmware upgrade.") + + if url: + # Download the firmware file from the URL + async with httpx.AsyncClient() as client: + response = await client.get(url) + if response.status_code != 200: + raise ValueError(f"Failed to download firmware from URL: {url}") + upgrade_contents = response.content + else: + # read the fimware file contents from the local file path + async with aiofiles.open(file_path, "rb") as f: + upgrade_contents = await f.read() + + logging.info("Firmware upgrade process completed successfully.") + return True + except Exception as e: + logging.error(f"An error occurred during the firmware upgrade process: {e}", exc_info=True) + return False + ################################################## ### DATA GATHERING FUNCTIONS (get_{some_data}) ### ################################################## @@ -385,28 +423,4 @@ class Auradine(StockFirmware): try: return rpc_summary["SUMMARY"][0]["Elapsed"] except LookupError: - pass - - async def upgrade_firmware(self, url: str = None, version: str = "latest") -> dict: - """ - Upgrade the firmware of the Auradine miner. - - Args: - url (str, optional): The URL to download the firmware from. - version (str, optional): The version of the firmware to upgrade to, defaults to 'latest'. - - Returns: - dict: A dictionary indicating the result of the firmware upgrade. - """ - try: - logging.info("Starting firmware upgrade process for Auradine miner.") - - if url is not None: - return await self.web.firmware_upgrade(url=url) - return await self.web.firmware_upgrade(version=version) - except Exception as e: - logging.error( - f"An unexpected error occurred during the firmware upgrade process: {e}", - exc_info=True, - ) - raise \ No newline at end of file + pass \ No newline at end of file diff --git a/pyasic/miners/base.py b/pyasic/miners/base.py index c66dc3b3..ca65fe93 100644 --- a/pyasic/miners/base.py +++ b/pyasic/miners/base.py @@ -16,6 +16,7 @@ import asyncio import ipaddress import warnings +import logging from typing import List, Optional, Protocol, Tuple, Type, TypeVar, Union from pyasic.config import MinerConfig @@ -560,5 +561,24 @@ class BaseMiner(MinerProtocol): if self._ssh_cls is not None: self.ssh = self._ssh_cls(ip) + async def upgrade_firmware(self, url: str = None, version: str = "latest") -> bool: + """Upgrade the firmware of the miner. + + Parameters: + url: The URL to download the firmware from. + version: The version of the firmware to upgrade to. + + Returns: + A boolean value of the success of the firmware upgrade. + """ + try: + if url is not None: + await self.web.send_command("firmware-upgrade", url=url) + else: + await self.web.send_command("firmware-upgrade", version=version) + return True + except Exception as e: + logging.error(f"Firmware upgrade failed: {e}") + return False AnyMiner = TypeVar("AnyMiner", bound=BaseMiner) \ No newline at end of file From 45e2c9a4036a4cd9d4fb17d99d38d711cc477c87 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Wed, 26 Jun 2024 19:06:51 +0530 Subject: [PATCH 06/13] modified upgrade_firmware for all subclasses --- pyasic/miners/base.py | 7 +++++-- pyasic/miners/device/firmware.py | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pyasic/miners/base.py b/pyasic/miners/base.py index ca65fe93..1ad18b6a 100644 --- a/pyasic/miners/base.py +++ b/pyasic/miners/base.py @@ -561,10 +561,11 @@ class BaseMiner(MinerProtocol): if self._ssh_cls is not None: self.ssh = self._ssh_cls(ip) - async def upgrade_firmware(self, url: str = None, version: str = "latest") -> bool: + async def upgrade_firmware(self, file: str = None, url: str = None, version: str = "latest") -> bool: """Upgrade the firmware of the miner. Parameters: + file: The file path to the firmware to upgrade from. url: The URL to download the firmware from. version: The version of the firmware to upgrade to. @@ -572,7 +573,9 @@ class BaseMiner(MinerProtocol): A boolean value of the success of the firmware upgrade. """ try: - if url is not None: + if file is not None: + await self.web.send_command("firmware-upgrade", file=file) + elif url is not None: await self.web.send_command("firmware-upgrade", url=url) else: await self.web.send_command("firmware-upgrade", version=version) diff --git a/pyasic/miners/device/firmware.py b/pyasic/miners/device/firmware.py index efd2b974..1c65e62e 100644 --- a/pyasic/miners/device/firmware.py +++ b/pyasic/miners/device/firmware.py @@ -21,26 +21,47 @@ from pyasic.miners.base import BaseMiner class StockFirmware(BaseMiner): firmware = MinerFirmware.STOCK + async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: + return await super().upgrade_firmware(url=url, version=version) + class BraiinsOSFirmware(BaseMiner): firmware = MinerFirmware.BRAIINS_OS + async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: + return await super().upgrade_firmware(url=url, version=version) + class VNishFirmware(BaseMiner): firmware = MinerFirmware.VNISH + async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: + return await super().upgrade_firmware(url=url, version=version) + class ePICFirmware(BaseMiner): firmware = MinerFirmware.EPIC + async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: + return await super().upgrade_firmware(url=url, version=version) + class HiveonFirmware(BaseMiner): firmware = MinerFirmware.HIVEON + async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: + return await super().upgrade_firmware(url=url, version=version) + class LuxOSFirmware(BaseMiner): firmware = MinerFirmware.LUXOS + async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: + return await super().upgrade_firmware(url=url, version=version) + class MaraFirmware(BaseMiner): firmware = MinerFirmware.MARATHON + + async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: + return await super().upgrade_firmware(url=url, version=version) From ba58e80ec31a4abf0aa4042a02addfb1bf0b11f5 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Thu, 27 Jun 2024 02:21:24 +0530 Subject: [PATCH 07/13] Add keep_setting arg in miners/base.py/BaseMiner/upgrade_firmware --- pyasic/miners/base.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pyasic/miners/base.py b/pyasic/miners/base.py index 1ad18b6a..e60fe896 100644 --- a/pyasic/miners/base.py +++ b/pyasic/miners/base.py @@ -561,27 +561,18 @@ class BaseMiner(MinerProtocol): if self._ssh_cls is not None: self.ssh = self._ssh_cls(ip) - async def upgrade_firmware(self, file: str = None, url: str = None, version: str = "latest") -> bool: + async def upgrade_firmware(self, *, file: str = None, url: str = None, version: str = "latest", keep_settings: bool = True) -> bool: """Upgrade the firmware of the miner. Parameters: file: The file path to the firmware to upgrade from. url: The URL to download the firmware from. version: The version of the firmware to upgrade to. + keep_settings: Whether to keep the current settings during the upgrade. Returns: A boolean value of the success of the firmware upgrade. """ - try: - if file is not None: - await self.web.send_command("firmware-upgrade", file=file) - elif url is not None: - await self.web.send_command("firmware-upgrade", url=url) - else: - await self.web.send_command("firmware-upgrade", version=version) - return True - except Exception as e: - logging.error(f"Firmware upgrade failed: {e}") - return False + return False AnyMiner = TypeVar("AnyMiner", bound=BaseMiner) \ No newline at end of file From e649348af2ca70fbc3055d6a0ddedd86f9942780 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Thu, 27 Jun 2024 03:43:33 +0530 Subject: [PATCH 08/13] used web attribute and removed some redundant changes from the firmware.py --- pyasic/miners/backends/auradine.py | 25 ++++++++++++++++--------- pyasic/miners/device/firmware.py | 23 +---------------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/pyasic/miners/backends/auradine.py b/pyasic/miners/backends/auradine.py index e574f4a6..690848d1 100644 --- a/pyasic/miners/backends/auradine.py +++ b/pyasic/miners/backends/auradine.py @@ -15,7 +15,7 @@ # ------------------------------------------------------------------------------ import logging from enum import Enum -import httpx +import base64 import aiofiles from typing import List, Optional @@ -195,7 +195,7 @@ class Auradine(StockFirmware): for key in conf.keys(): await self.web.send_command(command=key, **conf[key]) - async def upgrade_firmware(self, url: str = None, file_path: str = None, version: str = "latest") -> bool: + async def upgrade_firmware(self, *, url: str = None, file_path: str = None, version: str = "latest") -> bool: """ Upgrade the firmware of the Auradine device. @@ -215,16 +215,23 @@ class Auradine(StockFirmware): if url: # Download the firmware file from the URL - async with httpx.AsyncClient() as client: - response = await client.get(url) - if response.status_code != 200: - raise ValueError(f"Failed to download firmware from URL: {url}") - upgrade_contents = response.content + response = await self.web.get(url) + if response.status_code != 200: + raise ValueError(f"Failed to download firmware from URL: {url}") + upgrade_contents = response.content else: - # read the fimware file contents from the local file path + # Read the firmware file contents from the local file path async with aiofiles.open(file_path, "rb") as f: upgrade_contents = await f.read() + # Encode the firmware contents in base64 + encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") + + # Upload the firmware file to the Auradine miner device + await self.ssh.send_command( + f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" + ) + logging.info("Firmware upgrade process completed successfully.") return True except Exception as e: @@ -423,4 +430,4 @@ class Auradine(StockFirmware): try: return rpc_summary["SUMMARY"][0]["Elapsed"] except LookupError: - pass \ No newline at end of file + pass diff --git a/pyasic/miners/device/firmware.py b/pyasic/miners/device/firmware.py index 1c65e62e..d75fa82b 100644 --- a/pyasic/miners/device/firmware.py +++ b/pyasic/miners/device/firmware.py @@ -21,47 +21,26 @@ from pyasic.miners.base import BaseMiner class StockFirmware(BaseMiner): firmware = MinerFirmware.STOCK - async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: - return await super().upgrade_firmware(url=url, version=version) - class BraiinsOSFirmware(BaseMiner): firmware = MinerFirmware.BRAIINS_OS - async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: - return await super().upgrade_firmware(url=url, version=version) - class VNishFirmware(BaseMiner): firmware = MinerFirmware.VNISH - async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: - return await super().upgrade_firmware(url=url, version=version) - class ePICFirmware(BaseMiner): firmware = MinerFirmware.EPIC - async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: - return await super().upgrade_firmware(url=url, version=version) - class HiveonFirmware(BaseMiner): firmware = MinerFirmware.HIVEON - async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: - return await super().upgrade_firmware(url=url, version=version) - class LuxOSFirmware(BaseMiner): firmware = MinerFirmware.LUXOS - async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: - return await super().upgrade_firmware(url=url, version=version) - class MaraFirmware(BaseMiner): - firmware = MinerFirmware.MARATHON - - async def upgrade_firmware(self, *, url: str = None, version: str = "latest") -> bool: - return await super().upgrade_firmware(url=url, version=version) + firmware = MinerFirmware.MARATHON \ No newline at end of file From ae3d38603ad8a5a86e152f1ccd67e11b1df6a518 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Sat, 29 Jun 2024 14:29:48 +0530 Subject: [PATCH 09/13] Removed unused import --- pyasic/miners/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyasic/miners/base.py b/pyasic/miners/base.py index e60fe896..576c0ea4 100644 --- a/pyasic/miners/base.py +++ b/pyasic/miners/base.py @@ -16,7 +16,6 @@ import asyncio import ipaddress import warnings -import logging from typing import List, Optional, Protocol, Tuple, Type, TypeVar, Union from pyasic.config import MinerConfig From 8664b5399111259fa0853a2e7e03641a0e46f6b8 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Fri, 26 Jul 2024 05:30:42 +0530 Subject: [PATCH 10/13] Fix request handling --- pyasic/miners/backends/auradine.py | 36 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/pyasic/miners/backends/auradine.py b/pyasic/miners/backends/auradine.py index 893f0770..ea8bf0be 100644 --- a/pyasic/miners/backends/auradine.py +++ b/pyasic/miners/backends/auradine.py @@ -214,28 +214,32 @@ class Auradine(StockFirmware): raise ValueError("Either URL or file path must be provided for firmware upgrade.") if url: - # Download the firmware file from the URL - response = await self.web.get(url) - if response.status_code != 200: - raise ValueError(f"Failed to download firmware from URL: {url}") - upgrade_contents = response.content - else: + result = await self.web.firmware_upgrade(url=url) + elif file_path: # Read the firmware file contents from the local file path async with aiofiles.open(file_path, "rb") as f: upgrade_contents = await f.read() - # Encode the firmware contents in base64 - encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") + # Encode the firmware contents in base64 + encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") - # Upload the firmware file to the Auradine miner device - await self.ssh.send_command( - f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" - ) + # Upload the firmware file to the Auradine miner device + await self.ssh.send_command( + f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" + ) + result = {"success": True} # Assuming success if no exception is raised + else: + result = await self.web.firmware_upgrade(version=version) + + if result.get("success", False): + logging.info("Firmware upgrade process completed successfully.") + return True + else: + logging.error(f"Firmware upgrade failed: {result.get('error', 'Unknown error')}") + return False - logging.info("Firmware upgrade process completed successfully.") - return True except Exception as e: - logging.error(f"An error occurred during the firmware upgrade process: {e}", exc_info=True) + logging.error(f"An error occurred during the firmware upgrade process: {str(e)}") return False ################################################## @@ -281,7 +285,7 @@ class Auradine(StockFirmware): except LookupError: pass - async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]: + async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]: if rpc_summary is None: try: rpc_summary = await self.rpc.summary() From 92f70c9a76c75c532983e9ed1d6cdfc3adba6cb1 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Sat, 27 Jul 2024 23:55:50 +0530 Subject: [PATCH 11/13] Add keep_settings arg and other reviews --- pyasic/miners/backends/auradine.py | 23 ++++------------------- pyasic/miners/base.py | 10 +++++----- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/pyasic/miners/backends/auradine.py b/pyasic/miners/backends/auradine.py index ea8bf0be..0425e387 100644 --- a/pyasic/miners/backends/auradine.py +++ b/pyasic/miners/backends/auradine.py @@ -15,8 +15,6 @@ # ------------------------------------------------------------------------------ import logging from enum import Enum -import base64 -import aiofiles from typing import List, Optional from pyasic.config import MinerConfig @@ -195,14 +193,14 @@ class Auradine(StockFirmware): for key in conf.keys(): await self.web.send_command(command=key, **conf[key]) - async def upgrade_firmware(self, *, url: str = None, file_path: str = None, version: str = "latest") -> bool: + async def upgrade_firmware(self, *, url: str = None, version: str = "latest", keep_settings: bool = False, **kwargs) -> bool: """ Upgrade the firmware of the Auradine device. Args: url (str): The URL to download the firmware from. - file_path (str): The local file path of the firmware to be uploaded. version (str): The version of the firmware to upgrade to. + keep_settings (bool): Whether to keep the current settings during the upgrade. Returns: bool: True if the firmware upgrade was successful, False otherwise. @@ -210,24 +208,11 @@ class Auradine(StockFirmware): try: logging.info("Starting firmware upgrade process.") - if not url and not file_path: - raise ValueError("Either URL or file path must be provided for firmware upgrade.") + if not url and not version: + raise ValueError("Either URL or version must be provided for firmware upgrade.") if url: result = await self.web.firmware_upgrade(url=url) - elif file_path: - # Read the firmware file contents from the local file path - async with aiofiles.open(file_path, "rb") as f: - upgrade_contents = await f.read() - - # Encode the firmware contents in base64 - encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") - - # Upload the firmware file to the Auradine miner device - await self.ssh.send_command( - f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" - ) - result = {"success": True} # Assuming success if no exception is raised else: result = await self.web.firmware_upgrade(version=version) diff --git a/pyasic/miners/base.py b/pyasic/miners/base.py index 3ec91703..eb690821 100644 --- a/pyasic/miners/base.py +++ b/pyasic/miners/base.py @@ -560,14 +560,14 @@ class BaseMiner(MinerProtocol): if self._ssh_cls is not None: self.ssh = self._ssh_cls(ip) - async def upgrade_firmware(self, *, file: str = None, url: str = None, version: str = "latest", keep_settings: bool = True) -> bool: + async def upgrade_firmware(self, *, file: str = None, url: str = None, version: str = None, keep_settings: bool = True) -> bool: """Upgrade the firmware of the miner. Parameters: - file: The file path to the firmware to upgrade from. - url: The URL to download the firmware from. - version: The version of the firmware to upgrade to. - keep_settings: Whether to keep the current settings during the upgrade. + file (str, optional): The file path to the firmware to upgrade from. Must be a valid file path if provided. + url (str, optional): The URL to download the firmware from. Must be a valid URL if provided. + version (str, optional): The version of the firmware to upgrade to. If None, the version will be inferred from the file or URL. + keep_settings (bool, optional): Whether to keep the current settings during the upgrade. Defaults to True. Returns: A boolean value of the success of the firmware upgrade. From 4b4670201af8b547f99503ea154483444e39cf2c Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Sat, 27 Jul 2024 23:58:57 +0530 Subject: [PATCH 12/13] Backed some previous changes --- pyasic/miners/backends/auradine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyasic/miners/backends/auradine.py b/pyasic/miners/backends/auradine.py index 0425e387..ec4ca5ef 100644 --- a/pyasic/miners/backends/auradine.py +++ b/pyasic/miners/backends/auradine.py @@ -270,7 +270,7 @@ class Auradine(StockFirmware): except LookupError: pass - async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]: + async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]: if rpc_summary is None: try: rpc_summary = await self.rpc.summary() From 962a32821977db2d9405d35bd7f516cbfcdacb4f Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Wed, 31 Jul 2024 13:23:37 +0530 Subject: [PATCH 13/13] Fixes result check --- pyasic/miners/backends/auradine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyasic/miners/backends/auradine.py b/pyasic/miners/backends/auradine.py index ec4ca5ef..0001efdc 100644 --- a/pyasic/miners/backends/auradine.py +++ b/pyasic/miners/backends/auradine.py @@ -216,7 +216,7 @@ class Auradine(StockFirmware): else: result = await self.web.firmware_upgrade(version=version) - if result.get("success", False): + if result.get("STATUS", [{}])[0].get("STATUS") == "S": logging.info("Firmware upgrade process completed successfully.") return True else: