migration-tools/0046-agent-sends-task-update-requrst-to-the-server.patch
2024-11-06 13:25:16 +08:00

73 lines
2.3 KiB
Diff

From a55f866eee6a937842777af38beee70ec1cad8e4 Mon Sep 17 00:00:00 2001
From: xuezhixin <xuezhixin@uniontech.com>
Date: Fri, 10 Nov 2023 14:55:44 +0800
Subject: [PATCH] =?UTF-8?q?agent=E5=90=91server=E5=8F=91=E9=80=81=E4=BB=BB?=
=?UTF-8?q?=E5=8A=A1=E6=9B=B4=E6=96=B0=E8=AF=B7=E6=B1=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sysmig_agent/agent_request.py | 49 +++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 sysmig_agent/agent_request.py
diff --git a/sysmig_agent/agent_request.py b/sysmig_agent/agent_request.py
new file mode 100644
index 0000000..31d0cfe
--- /dev/null
+++ b/sysmig_agent/agent_request.py
@@ -0,0 +1,49 @@
+# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
+# SPDX-License-Identifier: MulanPubL-2.0-or-later
+
+import requests
+import json
+from sysmig_agent.share import getSysMigConf ,json_list_to_json, sql_online_statue
+
+uos_sysmig_conf = json.loads(getSysMigConf())
+ip = json.loads(uos_sysmig_conf).get('serverip').strip()[1:-1]
+port = int(json.loads(uos_sysmig_conf).get('serverport').strip()[1:-1])
+mod_sql = '/sql_task'
+
+headers = {'content-type': 'application/json'}
+
+
+class PostIntranetIP:
+ def __init__(self, url, data):
+ self.url = url
+ self.data = data
+
+ def post_intranetip(self):
+ try:
+ r = requests.post(url=self.url, data=self.data, headers=headers)
+ except:
+ r = None
+ return r
+
+
+def post_client_data(data):
+ post_url = "http://" + ip + ":" + str(port) + mod_sql
+ print('______>post:'+post_url+'\n____> data: '+str(data) +'ip port '+ip+str(port))
+ post_data = PostIntranetIP(post_url, data)
+ return post_data.post_intranetip()
+
+
+def post_server(statue, task_id):
+ keylist = ['mod','statue','task_id']
+ valuelist = ['sql_task',statue,str(task_id)]
+ data = json_list_to_json(keylist,valuelist)
+
+# data={"mod":"sql_task", "statue": "task_start", "task_id":2}
+ t = post_client_data(data)
+ print("requires post return code :"+str(t))
+ f = 0
+ if not t or t.status_code != 200:
+ t = post_client_data(data)
+ sql_online_statue(1, task_id)
+ else:
+ sql_online_statue(0, task_id)
--
2.20.1