From 6725378c0a35beed675d7cb73e1f16c712ece59a Mon Sep 17 00:00:00 2001
From: lixin <lixinb@uniontech.com>
Date: Thu, 9 Nov 2023 17:13:41 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4=E4=B8=BB?=
 =?UTF-8?q?=E6=9C=BA=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 index.py        | 13 +++++++++++++
 views/server.py | 23 ++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/index.py b/index.py
index 059431b..c51a24c 100644
--- a/index.py
+++ b/index.py
@@ -28,8 +28,10 @@ mods = {
         'import_host_info': server.import_host_info,
         'host_info_display': server.host_info_display,
         'sql_task': server.modify_task_stream,
+        'delete_host_info': server.delete_host_info,
         }
 
+
 @app.route('/import_host_info', methods=['GET', 'POST'])
 def import_host_info():
     """
@@ -63,6 +65,17 @@ def modify_task_stream():
         return Response(mod, content_type='application/json')
 
 
+@app.route('/delete_host_info', methods=['GET', 'POST'])
+def delete_host_info():
+    """
+    删除迁移主机
+    :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 a00e696..e7570b8 100644
--- a/views/server.py
+++ b/views/server.py
@@ -161,4 +161,25 @@ def modify_task_stream(data):
     modify_task_stream_sql = "update task_stream set stream_status='%s',stream_Updatetime='%s' " \
                              "where task_stream_id='%s';" % (task_status, time, task_stream_id)
     DBHelper().execute(modify_task_stream_sql)
-    return 'success'
\ No newline at end of file
+    return 'success'
+
+
+def delete_host_info(data):
+    """
+    删除主机信息
+    :return:
+    """
+    data = json.loads(data)
+    for i in data.get('agent_ip'):
+        sql = "delete from agent_info where agent_ip='%s';" % i
+        DBHelper().execute(sql)
+        sql = "delete from agent_task where agent_ip='%s';" % i
+        DBHelper().execute(sql)
+        sql = "delete from task_stream where agent_ip='%s';" % i
+        DBHelper().execute(sql)
+        sql = "delete from cur_task where agent_ip='%s';" % i
+        DBHelper().execute(sql)
+
+    res = {'data': 'success'}
+    json_res = json.dumps(res)
+    return json_res
\ No newline at end of file
-- 
2.20.1

