added send command option in the window
This commit is contained in:
@@ -25,7 +25,7 @@ class BOSMiner(BaseMiner):
|
|||||||
# return created connection
|
# return created connection
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
async def send_ssh_command(self, cmd: str) -> None:
|
async def send_ssh_command(self, cmd: str):
|
||||||
"""Sends SSH command to miner."""
|
"""Sends SSH command to miner."""
|
||||||
# creates result variable
|
# creates result variable
|
||||||
result = None
|
result = None
|
||||||
@@ -42,17 +42,8 @@ class BOSMiner(BaseMiner):
|
|||||||
if i == 3:
|
if i == 3:
|
||||||
return
|
return
|
||||||
continue
|
continue
|
||||||
|
return result
|
||||||
|
|
||||||
# let the user know the result of the command
|
|
||||||
if result is not None:
|
|
||||||
if result.stdout != "":
|
|
||||||
print(result.stdout)
|
|
||||||
if result.stderr != "":
|
|
||||||
print("ERROR: " + result.stderr)
|
|
||||||
elif result.stderr != "":
|
|
||||||
print("ERROR: " + result.stderr)
|
|
||||||
else:
|
|
||||||
print(cmd)
|
|
||||||
|
|
||||||
async def fault_light_on(self) -> None:
|
async def fault_light_on(self) -> None:
|
||||||
"""Sends command to turn on fault light on the miner."""
|
"""Sends command to turn on fault light on the miner."""
|
||||||
|
|||||||
@@ -72,31 +72,7 @@ class CGMiner(BaseMiner):
|
|||||||
if i == 3:
|
if i == 3:
|
||||||
return
|
return
|
||||||
continue
|
continue
|
||||||
# handle result
|
return result
|
||||||
self._result_handler(result)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _result_handler(result: asyncssh.process.SSHCompletedProcess) -> None:
|
|
||||||
if result is not None:
|
|
||||||
# noinspection PyUnresolvedReferences
|
|
||||||
if len(result.stdout) > 0:
|
|
||||||
# noinspection PyUnresolvedReferences
|
|
||||||
print("ssh stdout: \n" + result.stdout)
|
|
||||||
# noinspection PyUnresolvedReferences
|
|
||||||
if len(result.stderr) > 0:
|
|
||||||
# noinspection PyUnresolvedReferences
|
|
||||||
print("ssh stderr: \n" + result.stderrr)
|
|
||||||
# noinspection PyUnresolvedReferences
|
|
||||||
if len(result.stdout) <= 0 and len(result.stderr) <= 0:
|
|
||||||
print("ssh stdout stderr empty")
|
|
||||||
# if result.stdout != "":
|
|
||||||
# print(result.stdout)
|
|
||||||
# if result.stderr != "":
|
|
||||||
# print("ERROR: " + result.stderr)
|
|
||||||
# elif result.stderr != "":
|
|
||||||
# print("ERROR: " + result.stderr)
|
|
||||||
# else:
|
|
||||||
# print(cmd)
|
|
||||||
|
|
||||||
async def restart_backend(self) -> None:
|
async def restart_backend(self) -> None:
|
||||||
await self.restart_cgminer()
|
await self.restart_cgminer()
|
||||||
@@ -133,4 +109,3 @@ class CGMiner(BaseMiner):
|
|||||||
self._result_handler(result)
|
self._result_handler(result)
|
||||||
self.config = result.stdout
|
self.config = result.stdout
|
||||||
print(str(self.config))
|
print(str(self.config))
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ def disable_buttons(func):
|
|||||||
"send_config",
|
"send_config",
|
||||||
"light",
|
"light",
|
||||||
"generate_config",
|
"generate_config",
|
||||||
|
"send_miner_ssh_command_window",
|
||||||
]
|
]
|
||||||
|
|
||||||
# handle the inner function that the decorator is wrapping
|
# handle the inner function that the decorator is wrapping
|
||||||
|
|||||||
@@ -78,6 +78,52 @@ async def flip_light(ip):
|
|||||||
await miner.fault_light_off()
|
await miner.fault_light_off()
|
||||||
|
|
||||||
|
|
||||||
|
async def send_command_generator(miners: list, command: str):
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
command_tasks = []
|
||||||
|
for miner in miners:
|
||||||
|
if len(command_tasks) >= CONFIG_THREADS:
|
||||||
|
cmd_sent = asyncio.as_completed(command_tasks)
|
||||||
|
command_tasks = []
|
||||||
|
for done in cmd_sent:
|
||||||
|
yield await done
|
||||||
|
command_tasks.append(loop.create_task(send_ssh_command(miner, command)))
|
||||||
|
cmd_sent = asyncio.as_completed(command_tasks)
|
||||||
|
for done in cmd_sent:
|
||||||
|
yield await done
|
||||||
|
|
||||||
|
|
||||||
|
async def send_ssh_command(miner, command: str):
|
||||||
|
proc = await miner.send_ssh_command(command)
|
||||||
|
return {"IP": miner.ip, "proc": proc}
|
||||||
|
|
||||||
|
|
||||||
|
async def send_miners_ssh_commands(ips: list, command: str, ssh_cmd_window):
|
||||||
|
get_miner_genenerator = miner_factory.get_miner_generator(ips)
|
||||||
|
all_miners = []
|
||||||
|
async for miner in get_miner_genenerator:
|
||||||
|
all_miners.append(miner)
|
||||||
|
|
||||||
|
data = []
|
||||||
|
send_cmd_generator = send_command_generator(all_miners, command)
|
||||||
|
async for command_sent in send_cmd_generator:
|
||||||
|
data.append(command_sent)
|
||||||
|
|
||||||
|
proc_table_data = [[ip, ""] for ip in ips]
|
||||||
|
for item in data:
|
||||||
|
|
||||||
|
if item["proc"].returncode == 0:
|
||||||
|
return_data = item["proc"].stdout
|
||||||
|
else:
|
||||||
|
return_data = item["proc"].stderr
|
||||||
|
if str(item["IP"]) in ips:
|
||||||
|
proc_table_index = ips.index(str(item["IP"]))
|
||||||
|
proc_table_data[proc_table_index] = [
|
||||||
|
str(item["IP"]), return_data.replace("\n", " "),
|
||||||
|
]
|
||||||
|
ssh_cmd_window["ssh_cmd_table"].update(proc_table_data)
|
||||||
|
|
||||||
|
|
||||||
async def reboot_generator(miners: list):
|
async def reboot_generator(miners: list):
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
reboot_tasks = []
|
reboot_tasks = []
|
||||||
|
|||||||
@@ -19,6 +19,20 @@ def copy_from_table(table):
|
|||||||
pyperclip.copy(copy_string)
|
pyperclip.copy(copy_string)
|
||||||
|
|
||||||
|
|
||||||
|
def copy_from_ssh_table(table):
|
||||||
|
selection = table.selection()
|
||||||
|
copy_values = []
|
||||||
|
for each in selection:
|
||||||
|
try:
|
||||||
|
value = ", ".join(table.item(each)["values"])
|
||||||
|
copy_values.append(str(value))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
copy_string = "\n".join(copy_values)
|
||||||
|
pyperclip.copy(copy_string)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def update_ui_with_data(key, message, append=False):
|
async def update_ui_with_data(key, message, append=False):
|
||||||
if append:
|
if append:
|
||||||
message = window[key].get_text() + message
|
message = window[key].get_text() + message
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ layout = [
|
|||||||
sg.Button("REFRESH DATA", key='refresh_data'),
|
sg.Button("REFRESH DATA", key='refresh_data'),
|
||||||
sg.Button("OPEN IN WEB", key='open_in_web'),
|
sg.Button("OPEN IN WEB", key='open_in_web'),
|
||||||
sg.Button("REBOOT", key='reboot_miners'),
|
sg.Button("REBOOT", key='reboot_miners'),
|
||||||
sg.Button("RESTART BACKEND", key='restart_miner_backend')],
|
sg.Button("RESTART BACKEND", key='restart_miner_backend'),
|
||||||
|
sg.Button("SEND SSH COMMAND", key='send_miner_ssh_command_window')],
|
||||||
|
|
||||||
[sg.Text("HR Total: ", pad=(0, 0)), sg.Text("", key="hr_total")],
|
[sg.Text("HR Total: ", pad=(0, 0)), sg.Text("", key="hr_total")],
|
||||||
])],
|
])],
|
||||||
@@ -102,4 +103,31 @@ def generate_config_layout():
|
|||||||
return config_layout
|
return config_layout
|
||||||
|
|
||||||
|
|
||||||
|
def send_ssh_cmd_layout(miner_list: list):
|
||||||
|
cmd_layout = [
|
||||||
|
[sg.Text('Command:', size=(9, 1)),
|
||||||
|
sg.InputText(key='ssh_command_window_cmd', do_not_clear=True, size=(95, 1)),
|
||||||
|
sg.Button("Send Command", key='ssh_command_window_send_cmd')
|
||||||
|
],
|
||||||
|
[sg.Text("")],
|
||||||
|
[sg.Table(
|
||||||
|
values=[[ip, ""] for ip in miner_list],
|
||||||
|
headings=["IP",
|
||||||
|
"Result"],
|
||||||
|
auto_size_columns=False,
|
||||||
|
max_col_width=15,
|
||||||
|
justification="center",
|
||||||
|
key="ssh_cmd_table",
|
||||||
|
col_widths=[15, 90],
|
||||||
|
background_color="white",
|
||||||
|
text_color="black",
|
||||||
|
size=(105, 27),
|
||||||
|
expand_x=True,
|
||||||
|
enable_click_events=True,
|
||||||
|
)]
|
||||||
|
|
||||||
|
]
|
||||||
|
return cmd_layout
|
||||||
|
|
||||||
|
|
||||||
window = sg.Window('Upstream Config Util', layout, icon=icon_of_window)
|
window = sg.Window('Upstream Config Util', layout, icon=icon_of_window)
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ import sys
|
|||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
|
||||||
from tools.cfg_util.cfg_util_sg.layout import window, generate_config_layout
|
from tools.cfg_util.cfg_util_sg.layout import window, generate_config_layout, send_ssh_cmd_layout
|
||||||
from tools.cfg_util.cfg_util_sg.func.miners import send_config, miner_light, refresh_data, generate_config, import_config, \
|
from tools.cfg_util.cfg_util_sg.func.miners import send_config, miner_light, refresh_data, generate_config, import_config, \
|
||||||
scan_and_get_data, restart_miners_backend, reboot_miners
|
scan_and_get_data, restart_miners_backend, reboot_miners, send_miners_ssh_commands
|
||||||
from tools.cfg_util.cfg_util_sg.func.files import import_iplist, \
|
from tools.cfg_util.cfg_util_sg.func.files import import_iplist, \
|
||||||
import_config_file, export_iplist, export_config_file, export_csv
|
import_config_file, export_iplist, export_config_file, export_csv
|
||||||
from tools.cfg_util.cfg_util_sg.func.ui import sort_data, copy_from_table
|
from tools.cfg_util.cfg_util_sg.func.decorators import disable_buttons
|
||||||
|
from tools.cfg_util.cfg_util_sg.func.ui import sort_data, copy_from_table, copy_from_ssh_table
|
||||||
|
|
||||||
from network import MinerNetwork
|
from network import MinerNetwork
|
||||||
|
|
||||||
@@ -54,6 +55,12 @@ async def ui():
|
|||||||
if event == "reboot_miners":
|
if event == "reboot_miners":
|
||||||
if len(window["ip_table"].Values) > 0:
|
if len(window["ip_table"].Values) > 0:
|
||||||
asyncio.create_task(reboot_miners([window['ip_table'].Values[item][0] for item in value['ip_table']]))
|
asyncio.create_task(reboot_miners([window['ip_table'].Values[item][0] for item in value['ip_table']]))
|
||||||
|
if event == "send_miner_ssh_command_window":
|
||||||
|
ips = [window['ip_table'].Values[item][0] for item in value['ip_table']]
|
||||||
|
if len(ips) == 0:
|
||||||
|
ips = [item[0] for item in window["ip_table"].Values]
|
||||||
|
if not len(ips) == 0:
|
||||||
|
await generate_ssh_cmd_ui(ips)
|
||||||
if event == 'light':
|
if event == 'light':
|
||||||
if len(window["ip_table"].Values) > 0:
|
if len(window["ip_table"].Values) > 0:
|
||||||
asyncio.create_task(miner_light([window['ip_table'].Values[item][0] for item in value['ip_table']]))
|
asyncio.create_task(miner_light([window['ip_table'].Values[item][0] for item in value['ip_table']]))
|
||||||
@@ -92,3 +99,21 @@ async def generate_config_ui():
|
|||||||
values['generate_config_window_allow_v2'])
|
values['generate_config_window_allow_v2'])
|
||||||
generate_config_window.close()
|
generate_config_window.close()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
|
async def generate_ssh_cmd_ui(selected_miners: list):
|
||||||
|
ssh_cmd_window = sg.Window("Send Command", send_ssh_cmd_layout(selected_miners), modal=True)
|
||||||
|
ssh_cmd_window.read(timeout=0)
|
||||||
|
table = ssh_cmd_window["ssh_cmd_table"].Widget
|
||||||
|
table.bind("<Control-Key-c>", lambda x: copy_from_ssh_table(table))
|
||||||
|
# left justify the results
|
||||||
|
table.column(1, anchor=tk.W)
|
||||||
|
while True:
|
||||||
|
event, values = ssh_cmd_window.read(timeout=0)
|
||||||
|
if event in (None, 'Close', sg.WIN_CLOSED):
|
||||||
|
break
|
||||||
|
if event == "ssh_command_window_send_cmd":
|
||||||
|
asyncio.create_task(send_miners_ssh_commands(selected_miners, values["ssh_command_window_cmd"], ssh_cmd_window))
|
||||||
|
if event == "__TIMEOUT__":
|
||||||
|
await asyncio.sleep(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user