feature: add set_static_ip and set_dhcp for bosminer.
This commit is contained in:
@@ -373,6 +373,52 @@ class BOSMiner(BaseMiner):
|
|||||||
else:
|
else:
|
||||||
return True
|
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}) ###
|
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
|
||||||
##################################################
|
##################################################
|
||||||
@@ -386,8 +432,6 @@ class BOSMiner(BaseMiner):
|
|||||||
except APIError:
|
except APIError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print(web_net_conf)
|
|
||||||
|
|
||||||
if isinstance(web_net_conf, dict):
|
if isinstance(web_net_conf, dict):
|
||||||
if "/cgi-bin/luci/admin/network/iface_status/lan" in web_net_conf.keys():
|
if "/cgi-bin/luci/admin/network/iface_status/lan" in web_net_conf.keys():
|
||||||
web_net_conf = web_net_conf[
|
web_net_conf = web_net_conf[
|
||||||
|
|||||||
@@ -248,7 +248,6 @@ class LUXMiner(BaseMiner):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
async def get_hashrate(self, api_summary: dict = None) -> Optional[float]:
|
async def get_hashrate(self, api_summary: dict = None) -> Optional[float]:
|
||||||
# get hr from API
|
|
||||||
if not api_summary:
|
if not api_summary:
|
||||||
try:
|
try:
|
||||||
api_summary = await self.api.summary()
|
api_summary = await self.api.summary()
|
||||||
|
|||||||
@@ -58,11 +58,13 @@ class BOSMinerWebAPI(BaseWebAPI):
|
|||||||
command: dict,
|
command: dict,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
url = f"http://{self.ip}/graphql"
|
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:
|
try:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
await self.auth(client)
|
await self.auth(client)
|
||||||
data = await client.post(url, json={"query": query})
|
data = await client.post(url, json=query)
|
||||||
except httpx.HTTPError:
|
except httpx.HTTPError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user