From 0b27400d271794bc80959a150010b9fdedb92325 Mon Sep 17 00:00:00 2001 From: UpstreamData Date: Tue, 27 Jun 2023 14:55:05 -0600 Subject: [PATCH] feature: add `set_static_ip` and `set_dhcp` for bosminer. --- pyasic/miners/backends/bosminer.py | 48 ++++++++++++++++++++++++++++-- pyasic/miners/backends/luxminer.py | 1 - pyasic/web/bosminer.py | 6 ++-- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/pyasic/miners/backends/bosminer.py b/pyasic/miners/backends/bosminer.py index 3f414fb3..ce32b108 100644 --- a/pyasic/miners/backends/bosminer.py +++ b/pyasic/miners/backends/bosminer.py @@ -373,6 +373,52 @@ class BOSMiner(BaseMiner): else: return True + async def set_static_ip( + self, + ip: str, + dns: str, + gateway: str, + subnet_mask: str = "255.255.255.0", + ): + cfg_data_lan = ( + "config interface 'lan'\n\toption type 'bridge'\n\toption ifname 'eth0'\n\toption proto 'static'\n\toption ipaddr '" + + ip + + "'\n\toption netmask '" + + subnet_mask + + "'\n\toption gateway '" + + gateway + + "'\n\toption dns '" + + dns + + "'" + ) + data = await self.send_ssh_command("cat /etc/config/network") + + split_data = data.split("\n\n") + for idx in range(len(split_data)): + if "config interface 'lan'" in split_data[idx]: + split_data[idx] = cfg_data_lan + config = "\n\n".join(split_data) + + conn = await self._get_ssh_connection() + + async with conn: + await conn.run("echo '" + config + "' > /etc/config/network") + + async def set_dhcp(self): + cfg_data_lan = "config interface 'lan'\n\toption type 'bridge'\n\toption ifname 'eth0'\n\toption proto 'dhcp'" + data = await self.send_ssh_command("cat /etc/config/network") + + split_data = data.split("\n\n") + for idx in range(len(split_data)): + if "config interface 'lan'" in split_data[idx]: + split_data[idx] = cfg_data_lan + config = "\n\n".join(split_data) + + conn = await self._get_ssh_connection() + + async with conn: + await conn.run("echo '" + config + "' > /etc/config/network") + ################################################## ### DATA GATHERING FUNCTIONS (get_{some_data}) ### ################################################## @@ -386,8 +432,6 @@ class BOSMiner(BaseMiner): except APIError: pass - print(web_net_conf) - if isinstance(web_net_conf, dict): if "/cgi-bin/luci/admin/network/iface_status/lan" in web_net_conf.keys(): web_net_conf = web_net_conf[ diff --git a/pyasic/miners/backends/luxminer.py b/pyasic/miners/backends/luxminer.py index 04e66037..1d675214 100644 --- a/pyasic/miners/backends/luxminer.py +++ b/pyasic/miners/backends/luxminer.py @@ -248,7 +248,6 @@ class LUXMiner(BaseMiner): pass async def get_hashrate(self, api_summary: dict = None) -> Optional[float]: - # get hr from API if not api_summary: try: api_summary = await self.api.summary() diff --git a/pyasic/web/bosminer.py b/pyasic/web/bosminer.py index 1a7316a8..978953ef 100644 --- a/pyasic/web/bosminer.py +++ b/pyasic/web/bosminer.py @@ -58,11 +58,13 @@ class BOSMinerWebAPI(BaseWebAPI): command: dict, ) -> dict: url = f"http://{self.ip}/graphql" - query = self.parse_command(command) + query = command + if command.get("query") is None: + query = {"query": self.parse_command(command)} try: async with httpx.AsyncClient() as client: await self.auth(client) - data = await client.post(url, json={"query": query}) + data = await client.post(url, json=query) except httpx.HTTPError: pass else: