Add keep_settings arg and other reviews

This commit is contained in:
1e9abhi1e10
2024-07-27 23:55:50 +05:30
parent 8664b53991
commit 92f70c9a76
2 changed files with 9 additions and 24 deletions

View File

@@ -15,8 +15,6 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import logging import logging
from enum import Enum from enum import Enum
import base64
import aiofiles
from typing import List, Optional from typing import List, Optional
from pyasic.config import MinerConfig from pyasic.config import MinerConfig
@@ -195,14 +193,14 @@ class Auradine(StockFirmware):
for key in conf.keys(): for key in conf.keys():
await self.web.send_command(command=key, **conf[key]) 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. Upgrade the firmware of the Auradine device.
Args: Args:
url (str): The URL to download the firmware from. 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. version (str): The version of the firmware to upgrade to.
keep_settings (bool): Whether to keep the current settings during the upgrade.
Returns: Returns:
bool: True if the firmware upgrade was successful, False otherwise. bool: True if the firmware upgrade was successful, False otherwise.
@@ -210,24 +208,11 @@ class Auradine(StockFirmware):
try: try:
logging.info("Starting firmware upgrade process.") logging.info("Starting firmware upgrade process.")
if not url and not file_path: if not url and not version:
raise ValueError("Either URL or file path must be provided for firmware upgrade.") raise ValueError("Either URL or version must be provided for firmware upgrade.")
if url: if url:
result = await self.web.firmware_upgrade(url=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: else:
result = await self.web.firmware_upgrade(version=version) result = await self.web.firmware_upgrade(version=version)

View File

@@ -560,14 +560,14 @@ class BaseMiner(MinerProtocol):
if self._ssh_cls is not None: if self._ssh_cls is not None:
self.ssh = self._ssh_cls(ip) 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. """Upgrade the firmware of the miner.
Parameters: Parameters:
file: The file path to the firmware to upgrade from. file (str, optional): The file path to the firmware to upgrade from. Must be a valid file path if provided.
url: The URL to download the firmware from. url (str, optional): The URL to download the firmware from. Must be a valid URL if provided.
version: The version of the firmware to upgrade to. 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: Whether to keep the current settings during the upgrade. keep_settings (bool, optional): Whether to keep the current settings during the upgrade. Defaults to True.
Returns: Returns:
A boolean value of the success of the firmware upgrade. A boolean value of the success of the firmware upgrade.