added the option to append the last octet of the IP address to the username when configuring
This commit is contained in:
@@ -110,7 +110,7 @@ async def bos_config_convert(config: dict):
|
||||
return yaml.dump(out_config, sort_keys=False)
|
||||
|
||||
|
||||
async def general_config_convert_bos(yaml_config):
|
||||
async def general_config_convert_bos(yaml_config, user_suffix: str = None):
|
||||
config = yaml.load(yaml_config, Loader=yaml.SafeLoader)
|
||||
out_config = {}
|
||||
for opt in config:
|
||||
@@ -169,9 +169,14 @@ async def general_config_convert_bos(yaml_config):
|
||||
out_config["group"][idx]["pool"][pool_idx]["url"] = config[opt][
|
||||
idx
|
||||
]["pools"][pool_idx]["url"]
|
||||
out_config["group"][idx]["pool"][pool_idx]["user"] = config[opt][
|
||||
idx
|
||||
]["pools"][pool_idx]["username"]
|
||||
username = config[opt][idx]["pools"][pool_idx]["username"]
|
||||
if user_suffix:
|
||||
if "." in username:
|
||||
username = f"{username}x{user_suffix}"
|
||||
else:
|
||||
username = f"{username}.{user_suffix}"
|
||||
out_config["group"][idx]["pool"][pool_idx]["user"] = username
|
||||
|
||||
out_config["group"][idx]["pool"][pool_idx]["password"] = config[
|
||||
opt
|
||||
][idx]["pools"][pool_idx]["password"]
|
||||
|
||||
@@ -13,18 +13,3 @@ class BOSMinerS9(BOSMiner):
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"BOSminerS9: {str(self.ip)}"
|
||||
|
||||
async def send_config(self, yaml_config) -> None:
|
||||
"""Configures miner with yaml config."""
|
||||
logging.debug(f"{self}: Sending config.")
|
||||
conf = await general_config_convert_bos(yaml_config)
|
||||
toml_conf = toml.dumps(conf)
|
||||
conf["format"]["model"] = "Antminer S9"
|
||||
async with (await self._get_ssh_connection()) as conn:
|
||||
logging.debug(f"{self}: Opening SFTP connection.")
|
||||
async with conn.start_sftp_client() as sftp:
|
||||
logging.debug(f"{self}: Opening config file.")
|
||||
async with sftp.open("/etc/bosminer.toml", "w+") as file:
|
||||
await file.write(toml_conf)
|
||||
logging.debug(f"{self}: Restarting BOSMiner")
|
||||
await conn.run("/etc/init.d/bosminer restart")
|
||||
|
||||
@@ -154,10 +154,16 @@ class BOSMiner(BaseMiner):
|
||||
logging.warning(f"Failed to get model for miner: {self}")
|
||||
return None
|
||||
|
||||
async def send_config(self, yaml_config) -> None:
|
||||
async def send_config(self, yaml_config, ip_user: bool = False) -> None:
|
||||
"""Configures miner with yaml config."""
|
||||
logging.debug(f"{self}: Sending config.")
|
||||
toml_conf = toml.dumps(await general_config_convert_bos(yaml_config))
|
||||
if ip_user:
|
||||
suffix = str(self.ip).split(".")[-1]
|
||||
toml_conf = toml.dumps(
|
||||
await general_config_convert_bos(yaml_config, user_suffix=suffix)
|
||||
)
|
||||
else:
|
||||
toml_conf = toml.dumps(await general_config_convert_bos(yaml_config))
|
||||
async with (await self._get_ssh_connection()) as conn:
|
||||
logging.debug(f"{self}: Opening SFTP connection.")
|
||||
async with conn.start_sftp_client() as sftp:
|
||||
|
||||
@@ -203,7 +203,7 @@ async def restart_miners_backend(ips: list):
|
||||
await update_ui_with_data("status", "")
|
||||
|
||||
|
||||
async def send_config_generator(miners: list, config):
|
||||
async def send_config_generator(miners: list, config, last_octet_ip_user: bool = False):
|
||||
loop = asyncio.get_event_loop()
|
||||
config_tasks = []
|
||||
for miner in miners:
|
||||
@@ -212,14 +212,16 @@ async def send_config_generator(miners: list, config):
|
||||
config_tasks = []
|
||||
for sent_config in configured:
|
||||
yield await sent_config
|
||||
config_tasks.append(loop.create_task(miner.send_config(config)))
|
||||
config_tasks.append(
|
||||
loop.create_task(miner.send_config(config, ip_user=last_octet_ip_user))
|
||||
)
|
||||
configured = asyncio.as_completed(config_tasks)
|
||||
for sent_config in configured:
|
||||
yield await sent_config
|
||||
|
||||
|
||||
@disable_buttons
|
||||
async def send_config(ips: list, config):
|
||||
async def send_config(ips: list, config, last_octet_ip: bool = False):
|
||||
await update_ui_with_data("status", "Configuring")
|
||||
await set_progress_bar_len(2 * len(ips))
|
||||
progress_bar_len = 0
|
||||
@@ -231,7 +233,9 @@ async def send_config(ips: list, config):
|
||||
progress_bar_len += 1
|
||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
||||
|
||||
config_sender_generator = send_config_generator(all_miners, config)
|
||||
config_sender_generator = send_config_generator(
|
||||
all_miners, config, last_octet_ip_user=last_octet_ip
|
||||
)
|
||||
async for _config_sender in config_sender_generator:
|
||||
progress_bar_len += 1
|
||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
||||
|
||||
@@ -95,7 +95,7 @@ layout = [
|
||||
sg.Button("LIGHT", key="light"),
|
||||
sg.Button("GENERATE", key="generate_config"),
|
||||
],
|
||||
[sg.Text("")],
|
||||
[sg.Checkbox("Append IP 4th Octet to Username", key="last_octet_user")],
|
||||
[sg.Multiline(size=(50, 28), key="config", do_not_clear=True)],
|
||||
]
|
||||
),
|
||||
|
||||
@@ -138,6 +138,7 @@ async def ui():
|
||||
for item in value["ip_table"]
|
||||
],
|
||||
value["config"],
|
||||
last_octet_ip=value["last_octet_user"],
|
||||
)
|
||||
)
|
||||
if event == "import_file_config":
|
||||
|
||||
Reference in New Issue
Block a user