release version 1.4 (#21)
* chore: init working on history functions rename classes * refac: remove raw-result option. I cannot find a use ( I have found it later on ) * chore: add basic history directory checking * chore: further expansion on the code. Now its christmas * chore: rework some code and make a logging/history feature workable --------- Co-authored-by: DaanSelen <dselen@systemec.nl>
This commit is contained in:
+13
-24
@@ -5,26 +5,26 @@ import meshctrl
|
||||
from time import sleep
|
||||
|
||||
# Local Python libraries/modules
|
||||
from modules.console import console
|
||||
from modules.utilities import transform
|
||||
from modules.console import Console
|
||||
from modules.utilities import Transform
|
||||
|
||||
intertask_delay = 1
|
||||
|
||||
class executor:
|
||||
class Executor:
|
||||
@staticmethod
|
||||
async def execute_meshbook(args: argparse.Namespace, session: meshctrl.Session, compiled_device_list: dict, meshbook: dict, group_list: dict) -> None:
|
||||
async def execute_meshbook(silent: bool, enable_shlex: bool, session: meshctrl.Session, compiled_device_list: dict, meshbook: dict, group_list: dict) -> dict:
|
||||
'''
|
||||
Actual function that handles meshbook execution, also responsible for formatting the resulting JSON.
|
||||
'''
|
||||
|
||||
responses_list = {}
|
||||
complete_log = {}
|
||||
targets = compiled_device_list["target_list"]
|
||||
offline = compiled_device_list["offline_list"]
|
||||
round = 1
|
||||
|
||||
for task in meshbook["tasks"]:
|
||||
console.nice_print(args,
|
||||
console.text_color.green + str(round) + ". Running: " + task["name"])
|
||||
Console.print_text(silent,
|
||||
Console.text_color.green + str(round) + ". Running: " + task["name"])
|
||||
|
||||
if "powershell" in meshbook and meshbook["powershell"]:
|
||||
response = await session.run_command(nodeids=targets, command=task["command"],powershell=True,ignore_output=False,timeout=1800)
|
||||
@@ -36,10 +36,10 @@ class executor:
|
||||
device_result = response[device]["result"]
|
||||
response[device]["result"] = device_result.replace("Run commands completed.", "")
|
||||
response[device]["device_id"] = device
|
||||
response[device]["device_name"] = await transform.translate_nodeid_to_name(device, group_list)
|
||||
response[device]["device_name"] = await Transform.translate_nodeid_to_name(device, group_list)
|
||||
task_batch.append(response[device])
|
||||
|
||||
responses_list["task_" + str(round)] = {
|
||||
complete_log["task_" + str(round)] = {
|
||||
"task_name": task["name"],
|
||||
"data": task_batch
|
||||
}
|
||||
@@ -47,20 +47,9 @@ class executor:
|
||||
sleep(intertask_delay) # Sleep for x amount of time.
|
||||
|
||||
for index, device in enumerate(offline): # Replace Device_id with actual human readable name
|
||||
device_name = await transform.translate_nodeid_to_name(device, group_list)
|
||||
device_name = await Transform.translate_nodeid_to_name(device, group_list)
|
||||
offline[index] = device_name
|
||||
responses_list["Offline"] = offline
|
||||
complete_log["Offline"] = offline
|
||||
|
||||
console.nice_print(args,
|
||||
console.text_color.reset + ("-" * 40))
|
||||
|
||||
if args.indent:
|
||||
if not args.raw_result:
|
||||
responses_list = transform.process_shell_response(args.shlex, responses_list)
|
||||
console.nice_print(args,
|
||||
json.dumps(responses_list,indent=4), True)
|
||||
|
||||
|
||||
else:
|
||||
console.nice_print(args,
|
||||
json.dumps(responses_list), True)
|
||||
# Return the result
|
||||
return Transform.process_shell_response(enable_shlex, complete_log)
|
||||
Reference in New Issue
Block a user