update verification method for host ip and check host status when query host detail

(cherry picked from commit ebc28d92cfd1a7578db9449bb6c342db096780c6)
This commit is contained in:
rabbitali 2023-12-21 11:35:14 +08:00 committed by openeuler-sync-bot
parent 575d81a8bf
commit bdb8d2f625
3 changed files with 152 additions and 1 deletions

View File

@ -0,0 +1,34 @@
From 4dcbd5294f781e71d609036b75922fcb09b469c9 Mon Sep 17 00:00:00 2001
From: rabbitali <wenxin32@foxmail.com>
Date: Wed, 20 Dec 2023 15:09:46 +0800
Subject: [PATCH] update verification method for host ip field
---
zeus/function/verify/host.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/zeus/function/verify/host.py b/zeus/function/verify/host.py
index 310373c..7dedfee 100644
--- a/zeus/function/verify/host.py
+++ b/zeus/function/verify/host.py
@@ -114,7 +114,7 @@ class AddHostSchema(Schema):
host_name = fields.String(
required=True, validate=[validate.Length(min=1, max=50), ValidateRules.space_character_check]
)
- host_ip = fields.IP(required=True)
+ host_ip = fields.String(required=True, validate=ValidateRules.ipv4_address_check)
ssh_pkey = fields.String(required=True, allow_none=True, validate=lambda s: 4096 >= len(s) >= 0)
ssh_port = fields.Integer(required=True, validate=lambda s: 65535 >= s > 0)
host_group_name = fields.String(required=True, validate=lambda s: 20 >= len(s) > 0)
@@ -144,7 +144,7 @@ class UpdateHostSchema(Schema):
password = fields.String(required=False, validate=lambda s: len(s) > 0)
ssh_port = fields.Integer(required=False, validate=lambda s: 65535 >= s > 0)
host_name = fields.String(
- required=True, validate=[validate.Length(min=1, max=50), ValidateRules.space_character_check]
+ required=False, validate=[validate.Length(min=1, max=50), ValidateRules.space_character_check]
)
host_group_name = fields.String(required=False, validate=lambda s: 20 >= len(s) > 0)
management = fields.Boolean(required=False, truthy={True}, falsy={False})
--
2.33.0

View File

@ -0,0 +1,111 @@
From 62e90ee407ab0f28c47fcd51fe8f1078810e7c94 Mon Sep 17 00:00:00 2001
From: rearcher <123781007@qq.com>
Date: Thu, 21 Dec 2023 10:15:07 +0800
Subject: [PATCH] check host status when query host detail
---
zeus/host_manager/view.py | 69 ++++++++-------------------------------
1 file changed, 13 insertions(+), 56 deletions(-)
diff --git a/zeus/host_manager/view.py b/zeus/host_manager/view.py
index 6b31d35..30d05a3 100644
--- a/zeus/host_manager/view.py
+++ b/zeus/host_manager/view.py
@@ -265,6 +265,15 @@ class GetHostInfo(BaseResponse):
)
if status == state.SUCCEED:
res["host_info"] = json.loads(host_info)
+
+ # check host status
+ if status == state.SSH_AUTHENTICATION_ERROR:
+ res['status'] = HostStatus.UNESTABLISHED
+ elif status == state.SSH_CONNECTION_ERROR:
+ res['status'] = HostStatus.OFFLINE
+ elif host['status'] != HostStatus.SCANNING:
+ res['status'] = HostStatus.ONLINE
+
return res
@staticmethod
@@ -282,63 +291,12 @@ class GetHostInfo(BaseResponse):
{
"host_id": host_id,
"host_info":{}
+ "status": null
}
...
]
"""
- return [{"host_id": host_id, "host_info": {}} for host_id in host_list]
-
- def analyse_query_result(self, all_host: List[str], multithreading_execute_result: List) -> List:
- """
- Analyze multi-threaded execution results,
- find out the data which fails to execute,
- and generate the final execution result.
- Args:
- all_host(list): e.g
- [host_id1, host_id2... ]
- multithreading_execute_result(list): e.g
- [
- {
- "host_id":"success host id",
- "host_info": {
- "cpu": {...},
- "os":" {...},
- "memory": {...}.
- "disk": [{...}]
- },
- }
- ]
-
- Returns:
- list: e.g
- [
- {
- "host_id":"success host id",
- "host_info": {
- "cpu": {...},
- "os":" {...},
- "memory": {...}.
- "disk": [{...}]
- },
- }.
- {
- "host_id":"fail host id",
- "host_info": {}
- }.
- ]
-
-
- """
- host_infos = []
- success_host = set()
- for result in multithreading_execute_result:
- if result.get('host_info'):
- host_infos.append(result)
- success_host.add(result.get('host_id'))
-
- fail_host = set(all_host) - success_host
- host_infos.extend(self.generate_fail_data(fail_host))
- return host_infos
+ return [{"host_id": host_id, "host_info": {}, "status": None} for host_id in host_list]
@BaseResponse.handle(schema=GetHostInfoSchema, proxy=HostProxy)
def post(self, callback: HostProxy, **params):
@@ -369,10 +327,9 @@ class GetHostInfo(BaseResponse):
# execute multi threading
multi_thread_handler = MultiThreadHandler(lambda p: self.get_host_info(*p), tasks, None)
multi_thread_handler.create_thread()
- result_list = multi_thread_handler.get_result()
+ host_infos = multi_thread_handler.get_result()
- # analyse execute result and generate target data format
- host_infos = self.analyse_query_result(params.get('host_list'), result_list)
+ callback.update_host_status(host_infos)
return self.response(code=state.SUCCEED, data={"host_infos": host_infos})
--
2.33.0

View File

@ -1,6 +1,6 @@
Name: aops-zeus
Version: v1.4.0
Release: 3
Release: 4
Summary: A host and user manager service which is the foundation of aops.
License: MulanPSL2
URL: https://gitee.com/openeuler/%{name}
@ -11,6 +11,8 @@ Patch0003: 0003-fix-search_key-validate.patch
Patch0004: 0004-add-rollback-task-execution-method.patch
Patch0005: 0005-fix-apollo-TimedCorrectTask.patch
Patch0006: 0006-update-verification-method-for-adding-host.patch
Patch0007: 0007-update-verification-method-for-host-ip-field.patch
Patch0008: 0008-check-host-status-when-query-host-detail.patch
BuildRequires: python3-setuptools
@ -51,6 +53,10 @@ cp -r database %{buildroot}/opt/aops/
%changelog
* Thu Dec 21 2023 wenxin<wenxin32@foxmail.com> - v1.4.0-4
- update verification method for host ip field
- check host status when query host detail
* Tue Dec 19 2023 wenxin<wenxin32@foxmail.com> - v1.4.0-3
- update verification method for adding host or updating host info
- fix apollo TimedCorrectTask