refactor: improve settings handling to not use a dataclass, and not use singleton.
This commit is contained in:
@@ -27,10 +27,10 @@ from typing import Literal, Union
|
|||||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||||
from passlib.handlers.md5_crypt import md5_crypt
|
from passlib.handlers.md5_crypt import md5_crypt
|
||||||
|
|
||||||
|
from pyasic import settings
|
||||||
from pyasic.API import BaseMinerAPI
|
from pyasic.API import BaseMinerAPI
|
||||||
from pyasic.errors import APIError
|
from pyasic.errors import APIError
|
||||||
from pyasic.misc import api_min_version
|
from pyasic.misc import api_min_version
|
||||||
from pyasic.settings import PyasicSettings
|
|
||||||
|
|
||||||
### IMPORTANT ###
|
### IMPORTANT ###
|
||||||
# you need to change the password of the miners using the Whatsminer
|
# you need to change the password of the miners using the Whatsminer
|
||||||
@@ -192,7 +192,7 @@ class BTMinerAPI(BaseMinerAPI):
|
|||||||
ip: str,
|
ip: str,
|
||||||
api_ver: str = "0.0.0",
|
api_ver: str = "0.0.0",
|
||||||
port: int = 4028,
|
port: int = 4028,
|
||||||
pwd: str = PyasicSettings().global_whatsminer_password,
|
pwd: str = settings.get("default_whatsminer_password", "admin"),
|
||||||
):
|
):
|
||||||
super().__init__(ip, port)
|
super().__init__(ip, port)
|
||||||
self.pwd = pwd
|
self.pwd = pwd
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and -
|
# See the License for the specific language governing permissions and -
|
||||||
# limitations under the License. -
|
# limitations under the License. -
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
from pyasic import settings
|
||||||
from pyasic.API.bmminer import BMMinerAPI
|
from pyasic.API.bmminer import BMMinerAPI
|
||||||
from pyasic.API.bosminer import BOSMinerAPI
|
from pyasic.API.bosminer import BOSMinerAPI
|
||||||
from pyasic.API.btminer import BTMinerAPI
|
from pyasic.API.btminer import BTMinerAPI
|
||||||
@@ -32,7 +33,6 @@ from pyasic.miners.base import AnyMiner
|
|||||||
from pyasic.miners.miner_factory import MinerFactory
|
from pyasic.miners.miner_factory import MinerFactory
|
||||||
from pyasic.miners.miner_listener import MinerListener
|
from pyasic.miners.miner_listener import MinerListener
|
||||||
from pyasic.network import MinerNetwork
|
from pyasic.network import MinerNetwork
|
||||||
from pyasic.settings import PyasicSettings
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"BMMinerAPI",
|
"BMMinerAPI",
|
||||||
@@ -53,5 +53,5 @@ __all__ = [
|
|||||||
"MinerFactory",
|
"MinerFactory",
|
||||||
"MinerListener",
|
"MinerListener",
|
||||||
"MinerNetwork",
|
"MinerNetwork",
|
||||||
"PyasicSettings",
|
"settings",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -16,18 +16,16 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyasic.settings import PyasicSettings
|
|
||||||
|
|
||||||
|
|
||||||
def init_logger():
|
def init_logger():
|
||||||
if PyasicSettings().logfile:
|
# if PyasicSettings().logfile:
|
||||||
logging.basicConfig(
|
# logging.basicConfig(
|
||||||
filename="logfile.txt",
|
# filename="logfile.txt",
|
||||||
filemode="a",
|
# filemode="a",
|
||||||
format="%(pathname)s:%(lineno)d in %(funcName)s\n[%(levelname)s][%(asctime)s](%(name)s) - %(message)s",
|
# format="%(pathname)s:%(lineno)d in %(funcName)s\n[%(levelname)s][%(asctime)s](%(name)s) - %(message)s",
|
||||||
datefmt="%x %X",
|
# datefmt="%x %X",
|
||||||
)
|
# )
|
||||||
else:
|
# else:
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format="%(pathname)s:%(lineno)d in %(funcName)s\n[%(levelname)s][%(asctime)s](%(name)s) - %(message)s",
|
format="%(pathname)s:%(lineno)d in %(funcName)s\n[%(levelname)s][%(asctime)s](%(name)s) - %(message)s",
|
||||||
datefmt="%x %X",
|
datefmt="%x %X",
|
||||||
@@ -35,10 +33,10 @@ def init_logger():
|
|||||||
|
|
||||||
_logger = logging.getLogger()
|
_logger = logging.getLogger()
|
||||||
|
|
||||||
if PyasicSettings().debug:
|
# if PyasicSettings().debug:
|
||||||
_logger.setLevel(logging.DEBUG)
|
# _logger.setLevel(logging.DEBUG)
|
||||||
logging.getLogger("asyncssh").setLevel(logging.DEBUG)
|
# logging.getLogger("asyncssh").setLevel(logging.DEBUG)
|
||||||
else:
|
# else:
|
||||||
_logger.setLevel(logging.WARNING)
|
_logger.setLevel(logging.WARNING)
|
||||||
logging.getLogger("asyncssh").setLevel(logging.WARNING)
|
logging.getLogger("asyncssh").setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import ipaddress
|
|||||||
import logging
|
import logging
|
||||||
from typing import AsyncIterator, List, Union
|
from typing import AsyncIterator, List, Union
|
||||||
|
|
||||||
|
from pyasic import settings
|
||||||
from pyasic.miners.miner_factory import AnyMiner, miner_factory
|
from pyasic.miners.miner_factory import AnyMiner, miner_factory
|
||||||
from pyasic.network.net_range import MinerNetworkRange
|
from pyasic.network.net_range import MinerNetworkRange
|
||||||
from pyasic.settings import PyasicSettings
|
|
||||||
|
|
||||||
|
|
||||||
class MinerNetwork:
|
class MinerNetwork:
|
||||||
@@ -108,7 +108,7 @@ class MinerNetwork:
|
|||||||
# clear cached miners
|
# clear cached miners
|
||||||
miner_factory.clear_cached_miners()
|
miner_factory.clear_cached_miners()
|
||||||
|
|
||||||
limit = asyncio.Semaphore(PyasicSettings().network_scan_threads)
|
limit = asyncio.Semaphore(settings.get("network_scan_threads", 300))
|
||||||
miners = await asyncio.gather(
|
miners = await asyncio.gather(
|
||||||
*[self.ping_and_get_miner(host, limit) for host in local_network.hosts()]
|
*[self.ping_and_get_miner(host, limit) for host in local_network.hosts()]
|
||||||
)
|
)
|
||||||
@@ -136,7 +136,7 @@ class MinerNetwork:
|
|||||||
local_network = self.get_network()
|
local_network = self.get_network()
|
||||||
|
|
||||||
# create a list of scan tasks
|
# create a list of scan tasks
|
||||||
limit = asyncio.Semaphore(PyasicSettings().network_scan_threads)
|
limit = asyncio.Semaphore(settings.get("network_scan_threads", 300))
|
||||||
miners = asyncio.as_completed(
|
miners = asyncio.as_completed(
|
||||||
[
|
[
|
||||||
loop.create_task(self.ping_and_get_miner(host, limit))
|
loop.create_task(self.ping_and_get_miner(host, limit))
|
||||||
@@ -191,12 +191,12 @@ class MinerNetwork:
|
|||||||
async def ping_miner(
|
async def ping_miner(
|
||||||
ip: ipaddress.ip_address, port=4028
|
ip: ipaddress.ip_address, port=4028
|
||||||
) -> Union[None, ipaddress.ip_address]:
|
) -> Union[None, ipaddress.ip_address]:
|
||||||
for i in range(PyasicSettings().network_ping_retries):
|
for i in range(settings.get("network_ping_retries", 1)):
|
||||||
try:
|
try:
|
||||||
connection_fut = asyncio.open_connection(str(ip), port)
|
connection_fut = asyncio.open_connection(str(ip), port)
|
||||||
# get the read and write streams from the connection
|
# get the read and write streams from the connection
|
||||||
reader, writer = await asyncio.wait_for(
|
reader, writer = await asyncio.wait_for(
|
||||||
connection_fut, timeout=PyasicSettings().network_ping_timeout
|
connection_fut, timeout=settings.get("network_ping_timeout", 3)
|
||||||
)
|
)
|
||||||
# immediately close connection, we know connection happened
|
# immediately close connection, we know connection happened
|
||||||
writer.close()
|
writer.close()
|
||||||
@@ -220,12 +220,12 @@ async def ping_miner(
|
|||||||
async def ping_and_get_miner(
|
async def ping_and_get_miner(
|
||||||
ip: ipaddress.ip_address, port=4028
|
ip: ipaddress.ip_address, port=4028
|
||||||
) -> Union[None, AnyMiner]:
|
) -> Union[None, AnyMiner]:
|
||||||
for i in range(PyasicSettings().network_ping_retries):
|
for i in range(settings.get("network_ping_retries", 1)):
|
||||||
try:
|
try:
|
||||||
connection_fut = asyncio.open_connection(str(ip), port)
|
connection_fut = asyncio.open_connection(str(ip), port)
|
||||||
# get the read and write streams from the connection
|
# get the read and write streams from the connection
|
||||||
reader, writer = await asyncio.wait_for(
|
reader, writer = await asyncio.wait_for(
|
||||||
connection_fut, timeout=PyasicSettings().network_ping_timeout
|
connection_fut, timeout=settings.get("network_ping_timeout", 3)
|
||||||
)
|
)
|
||||||
# immediately close connection, we know connection happened
|
# immediately close connection, we know connection happened
|
||||||
writer.close()
|
writer.close()
|
||||||
|
|||||||
@@ -14,27 +14,26 @@
|
|||||||
# limitations under the License. -
|
# limitations under the License. -
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from typing import Any
|
||||||
|
|
||||||
from pyasic.misc import Singleton
|
_settings = { # defaults
|
||||||
|
"network_ping_retries": 1,
|
||||||
|
"network_ping_timeout": 3,
|
||||||
|
"network_scan_threads": 300,
|
||||||
|
"factory_get_retries": 1,
|
||||||
|
"get_data_retries": 1,
|
||||||
|
"default_whatsminer_password": "admin",
|
||||||
|
"default_innosilicon_password": "admin",
|
||||||
|
"default_antminer_password": "root",
|
||||||
|
"default_bosminer_password": "root",
|
||||||
|
"default_vnish_password": "admin",
|
||||||
|
"default_goldshell_password": "123456789",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
def get(key: str, other: Any = None) -> Any:
|
||||||
class PyasicSettings(metaclass=Singleton):
|
return _settings.get(key, other)
|
||||||
network_ping_retries: int = 1
|
|
||||||
network_ping_timeout: int = 3
|
|
||||||
network_scan_threads: int = 300
|
|
||||||
|
|
||||||
miner_factory_get_version_retries: int = 1
|
|
||||||
|
|
||||||
miner_get_data_retries: int = 1
|
def update(key: str, val: Any) -> Any:
|
||||||
|
_settings[key] = val
|
||||||
global_whatsminer_password = "admin"
|
|
||||||
global_innosilicon_password = "admin"
|
|
||||||
global_antminer_password = "root"
|
|
||||||
global_bosminer_password = "root"
|
|
||||||
global_vnish_password = "admin"
|
|
||||||
global_goldshell_password = "123456789"
|
|
||||||
|
|
||||||
debug: bool = False
|
|
||||||
logfile: bool = False
|
|
||||||
|
|||||||
@@ -19,14 +19,14 @@ from typing import Union
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from pyasic.settings import PyasicSettings
|
from pyasic import settings
|
||||||
from pyasic.web import BaseWebAPI
|
from pyasic.web import BaseWebAPI
|
||||||
|
|
||||||
|
|
||||||
class AntminerModernWebAPI(BaseWebAPI):
|
class AntminerModernWebAPI(BaseWebAPI):
|
||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
self.pwd = PyasicSettings().global_antminer_password
|
self.pwd = settings.get("default_antminer_password", "root")
|
||||||
|
|
||||||
async def send_command(
|
async def send_command(
|
||||||
self,
|
self,
|
||||||
@@ -137,7 +137,7 @@ class AntminerModernWebAPI(BaseWebAPI):
|
|||||||
class AntminerOldWebAPI(BaseWebAPI):
|
class AntminerOldWebAPI(BaseWebAPI):
|
||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
self.pwd = PyasicSettings().global_antminer_password
|
self.pwd = settings.get("default_antminer_password", "root")
|
||||||
|
|
||||||
async def send_command(
|
async def send_command(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -18,27 +18,14 @@ from typing import Union
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from pyasic import APIError
|
from pyasic import APIError, settings
|
||||||
from pyasic.settings import PyasicSettings
|
|
||||||
from pyasic.web import BaseWebAPI
|
from pyasic.web import BaseWebAPI
|
||||||
|
|
||||||
|
|
||||||
class BOSMinerWebAPI(BaseWebAPI):
|
class BOSMinerWebAPI(BaseWebAPI):
|
||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
self.gql = BOSMinerGQLAPI(ip, PyasicSettings().global_bosminer_password)
|
|
||||||
self.luci = BOSMinerLuCIAPI(ip, PyasicSettings().global_bosminer_password)
|
|
||||||
self._pwd = PyasicSettings().global_bosminer_password
|
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
|
self.pwd = settings.get("default_bosminer_password", "root")
|
||||||
@property
|
|
||||||
def pwd(self):
|
|
||||||
return self._pwd
|
|
||||||
|
|
||||||
@pwd.setter
|
|
||||||
def pwd(self, other: str):
|
|
||||||
self._pwd = other
|
|
||||||
self.luci.pwd = other
|
|
||||||
self.gql.pwd = other
|
|
||||||
|
|
||||||
async def send_command(
|
async def send_command(
|
||||||
self,
|
self,
|
||||||
@@ -47,70 +34,25 @@ class BOSMinerWebAPI(BaseWebAPI):
|
|||||||
allow_warning: bool = True,
|
allow_warning: bool = True,
|
||||||
**parameters: Union[str, int, bool],
|
**parameters: Union[str, int, bool],
|
||||||
) -> dict:
|
) -> dict:
|
||||||
if command.startswith("/cgi-bin/luci"):
|
if isinstance(command, str):
|
||||||
return await self.luci.send_command(command)
|
return await self.send_luci_command(command)
|
||||||
else:
|
else:
|
||||||
return await self.gql.send_command(command)
|
return await self.send_gql_command(command)
|
||||||
|
|
||||||
async def multicommand(
|
def parse_command(self, graphql_command: Union[dict, set]) -> str:
|
||||||
self, *commands: Union[dict, str], allow_warning: bool = True
|
if isinstance(graphql_command, dict):
|
||||||
) -> dict:
|
data = []
|
||||||
luci_commands = []
|
for key in graphql_command:
|
||||||
gql_commands = []
|
if graphql_command[key] is not None:
|
||||||
for cmd in commands:
|
parsed = self.parse_command(graphql_command[key])
|
||||||
if cmd.startswith("/cgi-bin/luci"):
|
data.append(key + parsed)
|
||||||
luci_commands.append(cmd)
|
|
||||||
if isinstance(cmd, dict):
|
|
||||||
gql_commands.append(cmd)
|
|
||||||
|
|
||||||
luci_data = await self.luci.multicommand(*luci_commands)
|
|
||||||
gql_data = await self.gql.multicommand(*gql_commands)
|
|
||||||
|
|
||||||
if gql_data is None:
|
|
||||||
gql_data = {}
|
|
||||||
if luci_data is None:
|
|
||||||
luci_data = {}
|
|
||||||
|
|
||||||
data = dict(**luci_data, **gql_data)
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
class BOSMinerGQLAPI:
|
|
||||||
def __init__(self, ip: str, pwd: str):
|
|
||||||
self.ip = ip
|
|
||||||
self.username = "root"
|
|
||||||
self.pwd = pwd
|
|
||||||
|
|
||||||
async def multicommand(self, *commands: dict) -> dict:
|
|
||||||
def merge(*d: dict):
|
|
||||||
ret = {}
|
|
||||||
for i in d:
|
|
||||||
if i:
|
|
||||||
for k in i:
|
|
||||||
if not k in ret:
|
|
||||||
ret[k] = i[k]
|
|
||||||
else:
|
else:
|
||||||
ret[k] = merge(ret[k], i[k])
|
data.append(key)
|
||||||
return None if ret == {} else ret
|
else:
|
||||||
|
data = graphql_command
|
||||||
|
return "{" + ",".join(data) + "}"
|
||||||
|
|
||||||
command = merge(*commands)
|
async def send_gql_command(
|
||||||
data = await self.send_command(command)
|
|
||||||
if data is not None:
|
|
||||||
if data.get("data") is None:
|
|
||||||
try:
|
|
||||||
commands = list(commands)
|
|
||||||
# noinspection PyTypeChecker
|
|
||||||
commands.remove({"bos": {"faultLight": None}})
|
|
||||||
command = merge(*commands)
|
|
||||||
data = await self.send_command(command)
|
|
||||||
except (LookupError, ValueError):
|
|
||||||
pass
|
|
||||||
if not data:
|
|
||||||
data = {}
|
|
||||||
data["multicommand"] = False
|
|
||||||
return data
|
|
||||||
|
|
||||||
async def send_command(
|
|
||||||
self,
|
self,
|
||||||
command: dict,
|
command: dict,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
@@ -131,18 +73,62 @@ class BOSMinerGQLAPI:
|
|||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def parse_command(self, graphql_command: Union[dict, set]) -> str:
|
async def multicommand(
|
||||||
if isinstance(graphql_command, dict):
|
self, *commands: Union[dict, str], allow_warning: bool = True
|
||||||
data = []
|
) -> dict:
|
||||||
for key in graphql_command:
|
luci_commands = []
|
||||||
if graphql_command[key] is not None:
|
gql_commands = []
|
||||||
parsed = self.parse_command(graphql_command[key])
|
for cmd in commands:
|
||||||
data.append(key + parsed)
|
if isinstance(cmd, dict):
|
||||||
|
gql_commands.append(cmd)
|
||||||
|
if isinstance(cmd, str):
|
||||||
|
luci_commands.append(cmd)
|
||||||
|
|
||||||
|
luci_data = await self.luci_multicommand(*luci_commands)
|
||||||
|
gql_data = await self.gql_multicommand(*gql_commands)
|
||||||
|
|
||||||
|
if gql_data is None:
|
||||||
|
gql_data = {}
|
||||||
|
if luci_data is None:
|
||||||
|
luci_data = {}
|
||||||
|
|
||||||
|
data = dict(**luci_data, **gql_data)
|
||||||
|
return data
|
||||||
|
|
||||||
|
async def luci_multicommand(self, *commands: str) -> dict:
|
||||||
|
data = {}
|
||||||
|
for command in commands:
|
||||||
|
data[command] = await self.send_luci_command(command, ignore_errors=True)
|
||||||
|
return data
|
||||||
|
|
||||||
|
async def gql_multicommand(self, *commands: dict) -> dict:
|
||||||
|
def merge(*d: dict):
|
||||||
|
ret = {}
|
||||||
|
for i in d:
|
||||||
|
if i:
|
||||||
|
for k in i:
|
||||||
|
if not k in ret:
|
||||||
|
ret[k] = i[k]
|
||||||
else:
|
else:
|
||||||
data.append(key)
|
ret[k] = merge(ret[k], i[k])
|
||||||
else:
|
return None if ret == {} else ret
|
||||||
data = graphql_command
|
|
||||||
return "{" + ",".join(data) + "}"
|
command = merge(*commands)
|
||||||
|
data = await self.send_command(command)
|
||||||
|
if data is not None:
|
||||||
|
if data.get("data") is None:
|
||||||
|
try:
|
||||||
|
commands = list(commands)
|
||||||
|
# noinspection PyTypeChecker
|
||||||
|
commands.remove({"bos": {"faultLight": None}})
|
||||||
|
command = merge(*commands)
|
||||||
|
data = await self.send_gql_command(command)
|
||||||
|
except (LookupError, ValueError):
|
||||||
|
pass
|
||||||
|
if not data:
|
||||||
|
data = {}
|
||||||
|
data["multicommand"] = False
|
||||||
|
return data
|
||||||
|
|
||||||
async def auth(self, client: httpx.AsyncClient) -> None:
|
async def auth(self, client: httpx.AsyncClient) -> None:
|
||||||
url = f"http://{self.ip}/graphql"
|
url = f"http://{self.ip}/graphql"
|
||||||
@@ -157,23 +143,10 @@ class BOSMinerGQLAPI:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def send_luci_command(self, path: str, ignore_errors: bool = False) -> dict:
|
||||||
class BOSMinerLuCIAPI:
|
|
||||||
def __init__(self, ip: str, pwd: str):
|
|
||||||
self.ip = ip
|
|
||||||
self.username = "root"
|
|
||||||
self.pwd = pwd
|
|
||||||
|
|
||||||
async def multicommand(self, *commands: str) -> dict:
|
|
||||||
data = {}
|
|
||||||
for command in commands:
|
|
||||||
data[command] = await self.send_command(command, ignore_errors=True)
|
|
||||||
return data
|
|
||||||
|
|
||||||
async def send_command(self, path: str, ignore_errors: bool = False) -> dict:
|
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
await self.auth(client)
|
await self.luci_auth(client)
|
||||||
data = await client.get(
|
data = await client.get(
|
||||||
f"http://{self.ip}{path}", headers={"User-Agent": "BTC Tools v0.1"}
|
f"http://{self.ip}{path}", headers={"User-Agent": "BTC Tools v0.1"}
|
||||||
)
|
)
|
||||||
@@ -189,7 +162,7 @@ class BOSMinerLuCIAPI:
|
|||||||
return {}
|
return {}
|
||||||
raise APIError(f"Web command failed: path={path}")
|
raise APIError(f"Web command failed: path={path}")
|
||||||
|
|
||||||
async def auth(self, session: httpx.AsyncClient):
|
async def luci_auth(self, session: httpx.AsyncClient):
|
||||||
login = {"luci_username": self.username, "luci_password": self.pwd}
|
login = {"luci_username": self.username, "luci_password": self.pwd}
|
||||||
url = f"http://{self.ip}/cgi-bin/luci"
|
url = f"http://{self.ip}/cgi-bin/luci"
|
||||||
headers = {
|
headers = {
|
||||||
@@ -199,27 +172,23 @@ class BOSMinerLuCIAPI:
|
|||||||
await session.post(url, headers=headers, data=login)
|
await session.post(url, headers=headers, data=login)
|
||||||
|
|
||||||
async def get_net_conf(self):
|
async def get_net_conf(self):
|
||||||
return await self.send_command("/cgi-bin/luci/admin/network/iface_status/lan")
|
return await self.send_luci_command(
|
||||||
|
"/cgi-bin/luci/admin/network/iface_status/lan"
|
||||||
|
)
|
||||||
|
|
||||||
async def get_cfg_metadata(self):
|
async def get_cfg_metadata(self):
|
||||||
return await self.send_command("/cgi-bin/luci/admin/miner/cfg_metadata")
|
return await self.send_luci_command("/cgi-bin/luci/admin/miner/cfg_metadata")
|
||||||
|
|
||||||
async def get_cfg_data(self):
|
async def get_cfg_data(self):
|
||||||
return await self.send_command("/cgi-bin/luci/admin/miner/cfg_data")
|
return await self.send_luci_command("/cgi-bin/luci/admin/miner/cfg_data")
|
||||||
|
|
||||||
async def get_bos_info(self):
|
async def get_bos_info(self):
|
||||||
return await self.send_command("/cgi-bin/luci/bos/info")
|
return await self.send_luci_command("/cgi-bin/luci/bos/info")
|
||||||
|
|
||||||
async def get_overview(self):
|
async def get_overview(self):
|
||||||
return await self.send_command(
|
return await self.send_luci_command(
|
||||||
"/cgi-bin/luci/admin/status/overview?status=1"
|
"/cgi-bin/luci/admin/status/overview?status=1"
|
||||||
) # needs status=1 or it fails
|
) # needs status=1 or it fails
|
||||||
|
|
||||||
async def get_api_status(self):
|
async def get_api_status(self):
|
||||||
return await self.send_command("/cgi-bin/luci/admin/miner/api_status")
|
return await self.send_luci_command("/cgi-bin/luci/admin/miner/api_status")
|
||||||
|
|
||||||
|
|
||||||
class BOSMinerGRPCAPI:
|
|
||||||
def __init__(self, ip: str, pwd: str):
|
|
||||||
self.ip = ip
|
|
||||||
self.pwd = pwd
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from typing import Union
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from pyasic.settings import PyasicSettings
|
from pyasic import settings
|
||||||
from pyasic.web import BaseWebAPI
|
from pyasic.web import BaseWebAPI
|
||||||
|
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ class GoldshellWebAPI(BaseWebAPI):
|
|||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
self.username = "admin"
|
self.username = "admin"
|
||||||
self.pwd = PyasicSettings().global_goldshell_password
|
self.pwd = settings.get("default_goldshell_password", "123456789")
|
||||||
self.jwt = None
|
self.jwt = None
|
||||||
|
|
||||||
async def auth(self):
|
async def auth(self):
|
||||||
@@ -72,7 +72,7 @@ class GoldshellWebAPI(BaseWebAPI):
|
|||||||
if not self.jwt:
|
if not self.jwt:
|
||||||
await self.auth()
|
await self.auth()
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
for i in range(PyasicSettings().miner_get_data_retries):
|
for i in range(settings.get("get_data_retries", 1)):
|
||||||
try:
|
try:
|
||||||
if parameters:
|
if parameters:
|
||||||
response = await client.put(
|
response = await client.put(
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ from typing import Union
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
|
from pyasic import settings
|
||||||
from pyasic.errors import APIError
|
from pyasic.errors import APIError
|
||||||
from pyasic.settings import PyasicSettings
|
|
||||||
from pyasic.web import BaseWebAPI
|
from pyasic.web import BaseWebAPI
|
||||||
|
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ class InnosiliconWebAPI(BaseWebAPI):
|
|||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
self.username = "admin"
|
self.username = "admin"
|
||||||
self.pwd = PyasicSettings().global_innosilicon_password
|
self.pwd = settings.get("default_innosilicon_password", "admin")
|
||||||
self.jwt = None
|
self.jwt = None
|
||||||
|
|
||||||
async def auth(self):
|
async def auth(self):
|
||||||
@@ -55,7 +55,7 @@ class InnosiliconWebAPI(BaseWebAPI):
|
|||||||
if not self.jwt:
|
if not self.jwt:
|
||||||
await self.auth()
|
await self.auth()
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
for i in range(PyasicSettings().miner_get_data_retries):
|
for i in range(settings.get("get_data_retries", 1)):
|
||||||
try:
|
try:
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
f"http://{self.ip}/api/{command}",
|
f"http://{self.ip}/api/{command}",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from typing import Union
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from pyasic.settings import PyasicSettings
|
from pyasic import settings
|
||||||
from pyasic.web import BaseWebAPI
|
from pyasic.web import BaseWebAPI
|
||||||
|
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ class VNishWebAPI(BaseWebAPI):
|
|||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
super().__init__(ip)
|
super().__init__(ip)
|
||||||
self.username = "admin"
|
self.username = "admin"
|
||||||
self.pwd = PyasicSettings().global_vnish_password
|
self.pwd = settings.get("default_vnish_password", "admin")
|
||||||
self.token = None
|
self.token = None
|
||||||
|
|
||||||
async def auth(self):
|
async def auth(self):
|
||||||
@@ -59,7 +59,7 @@ class VNishWebAPI(BaseWebAPI):
|
|||||||
if not self.token:
|
if not self.token:
|
||||||
await self.auth()
|
await self.auth()
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
for i in range(PyasicSettings().miner_get_data_retries):
|
for i in range(settings.get("get_data_retries", 1)):
|
||||||
try:
|
try:
|
||||||
auth = self.token
|
auth = self.token
|
||||||
if command.startswith("system"):
|
if command.startswith("system"):
|
||||||
|
|||||||
Reference in New Issue
Block a user