MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / create_cmd_task

Method create_cmd_task

mod/project/node/dbutil/node_task_flow.py:900–948  ·  view source on GitHub ↗
(self,
                        flow_id: int, step_index: int, task_data: dict,
                        nodes: List[Dict])

Source from the content-addressed store, hash-verified

898 return f, ""
899
900 def create_cmd_task(self,
901 flow_id: int, step_index: int, task_data: dict,
902 nodes: List[Dict]) -> Tuple[Optional[CommandTask], str]:
903
904 script_id = task_data.get('script_id', 0)
905 script_content = task_data.get('script_content', "").strip()
906 script_type = task_data.get('script_type', "").strip()
907 name = task_data.get('name', random_name())
908 if script_id:
909 s = self.Script.get_byid(script_id)
910 if not s:
911 return None, "脚本不存在"
912 script_content = s.content
913 script_type = s.script_type
914 elif script_content:
915 if not script_type in ("python", "shell"):
916 return None, "脚本类型错误"
917 else:
918 return None, "未选择脚本"
919
920 cmd_task = CommandTask(
921 flow_id=flow_id,
922 step_index=step_index,
923 script_id=script_id,
924 name=name,
925 script_content=script_content,
926 script_type=script_type,
927 )
928 task_id = self.CommandTask.create(cmd_task)
929 if not isinstance(task_id, int):
930 return None, str(task_id)
931 cmd_task.id = task_id
932 time_now = time.time()
933 md5_str = public.md5(script_content)[::2]
934 cmd_logs = [
935 CommandLog(
936 command_task_id=task_id,
937 server_id=node["id"],
938 ssh_host=node["ssh_conf"]["host"],
939 log_name="{}_{}_{}.log".format(md5_str, time_now, node['remarks'])
940 )
941 for node in nodes
942 ]
943 res = self.CommandLog.create(cmd_logs)
944 if not isinstance(res, int):
945 self.CommandTask.delete(task_id)
946 return None, str(res)
947 cmd_task.elogs = cmd_logs
948 return cmd_task, ""
949
950 def create_transfer_task(
951 self, flow_id: int, step_index: int, task_data: dict,

Callers 1

create_flowMethod · 0.95

Calls 10

random_nameFunction · 0.85
CommandTaskClass · 0.85
CommandLogClass · 0.85
timeMethod · 0.80
getMethod · 0.45
get_byidMethod · 0.45
createMethod · 0.45
md5Method · 0.45
formatMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected