diff --git a/0013-display-agent-host-information.patch b/0013-display-agent-host-information.patch new file mode 100644 index 0000000000000000000000000000000000000000..def9fbfbea8e1d2a7e774a83161ccfa221b5c028 --- /dev/null +++ b/0013-display-agent-host-information.patch @@ -0,0 +1,124 @@ +From 2140a85929564d0104bc364cd4e306f75c7dc77d Mon Sep 17 00:00:00 2001 +From: lixin +Date: Thu, 9 Nov 2023 16:35:55 +0800 +Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=BB=E6=9C=BA=E4=BF=A1?= + =?UTF-8?q?=E6=81=AF=E5=B1=95=E7=A4=BA?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + index.py | 13 +++++++++++ + views/server.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++-- + 2 files changed, 70 insertions(+), 2 deletions(-) + +diff --git a/index.py b/index.py +index 2cb89aa..0c64990 100644 +--- a/index.py ++++ b/index.py +@@ -27,6 +27,7 @@ mods = { + 'system_migration': migration.system_migration, + 'migration_details': migration.migration_details, + 'import_host_info': server.import_host_info, ++ 'host_info_display': server.host_info_display, + } + + @app.route('/import_host_info', methods=['GET', 'POST']) +@@ -39,6 +40,18 @@ def import_host_info(): + if mod: + return Response(mod, content_type='application/json') + ++ ++@app.route('/host_info_display', methods=['GET', 'POST']) ++def host_info_display(): ++ """ ++ 显示主机信息 ++ :return: ++ """ ++ mod = check_methods() ++ if mod: ++ return Response(mod, content_type='application/json') ++ ++ + def check_methods(): + if request.method == 'POST': + data = request.get_data() +diff --git a/views/server.py b/views/server.py +index cf07d2f..d2ca719 100644 +--- a/views/server.py ++++ b/views/server.py +@@ -38,7 +38,6 @@ def import_host_info(data): + return data_json + + +- + def get_agent_id(agent_ip): + """ + 获取agent_id +@@ -77,4 +76,60 @@ def create_task_stream(agent_ip): + create_agent_task_sql = "insert into agent_task(agent_id,agent_ip,task_id,task_status,task_progress," \ + "task_CreateTime,task_Updatetime,task_stream_id,task_data) values " \ + "(%s, %s, %s, %s, %s, %s, %s, %s, %s);" +- DBHelper().insert(create_agent_task_sql, values) +\ No newline at end of file ++ DBHelper().insert(create_agent_task_sql, values) ++ ++ ++def pagebreak(data, page, size): ++ """ ++ 页面数据分页 ++ :param data: ++ :return: ++ """ ++ page_start = (page - 1) * size ++ page_end = page * size ++ result = data[page_start:page_end] ++ ++ return result ++ ++def host_info_display(data): ++ """ ++ 显示主机信息 ++ agent_ip,hostname,agent_online_status,agent_os,agent_arch, ++ agent_history_faild_reason,task_CreateTime,task_status ++ :return: ++ """ ++ page = json.loads(data).get('page') ++ size = json.loads(data).get('size') ++ sql = "select agent_ip,hostname,agent_online_status,agent_os,agent_arch," \ ++ "agent_history_faild_reason from agent_info;" ++ data = DBHelper().execute(sql).fetchall() ++ data = list(data) ++ for i in range(0, len(data)): ++ data[i] = list(data[i]) ++ agent_task = "select task_CreateTime,task_data from agent_task where agent_ip = '%s';" % data[i][0] ++ get_agent_task = DBHelper().execute(agent_task).fetchall() ++ get_agent_task = list(get_agent_task) ++ ++ if not get_agent_task: ++ data[i] += ["", ""] ++ else: ++ task_CreateTime = get_agent_task[0][0].strftime('%Y-%-m-%d %H:%M:%S') ++ task_status = get_agent_task[0][1] ++ data[i].append(task_CreateTime) ++ data[i].append(task_status) ++ ++ res = {} ++ res['num'] = len(data) ++ info_list = [] ++ info_dict_keys_list = ['agent_ip', 'hostname', 'agent_online_status', 'agent_os', 'agent_arch', ++ 'failure_reasons', 'task_CreateTime', 'task_status'] ++ for i in data: ++ info_list.append(dict(zip(info_dict_keys_list, i))) ++ ++ page_list = pagebreak(info_list, page, size) ++ res['info'] = page_list ++ res['page'] = page ++ res['size'] = size ++ ++ json_res = json.dumps(res) ++ return json_res +\ No newline at end of file +-- +2.20.1 + diff --git a/migration-tools.spec b/migration-tools.spec index b1daf7666fe671fd1ef21f66304aaab4ffee1e16..b1275fbd47824b62acf19f2af5b838c15d05477d 100644 --- a/migration-tools.spec +++ b/migration-tools.spec @@ -1,6 +1,6 @@ Name: migration-tools Version: 1.0.2 -Release: 12 +Release: 13 License: MulanPSL-2.0 Summary: A tool to help users migrate the Centos system to the UOS system and openEuler system Source0: %{name}-%{version}.tar.gz @@ -19,6 +19,7 @@ Patch8: 0009-add-task_stream-table-in-database.patch Patch10: 0010-create-task-stream-interface.patch Patch11: 0011-replace-agent-with-func-diractory.patch Patch12: 0012-add-agent_task-in-database.patch +Patch13: 0013-display-agent-host-information.patch BuildArch: noarch BuildRequires: systemd @@ -117,6 +118,9 @@ rm -rf /usr/bin/migration-tools %endif %changelog +* Mon Nov 4 2024 xuezhixin - 1.0.2-13 +- 0013-display-agent-host-information.patch + * Mon Nov 4 2024 xuezhixin - 1.0.2-12 - 0012-add-agent_task-in-database.patch