From 929d9b3ce4e9d5a02361c2591a51c342dd483bc9 Mon Sep 17 00:00:00 2001 From: yinlei Date: Tue, 6 Aug 2024 23:13:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=20Jumpserver?= =?UTF-8?q?=20V3=20=E5=90=8C=E6=AD=A5=20ECS=20=E6=97=B6=EF=BC=8C=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E6=89=8B=E5=8A=A8=E6=9B=B4=E6=94=B9=E8=BF=87=E7=9A=84?= =?UTF-8?q?=20SSH=20=E7=AB=AF=E5=8F=A3=E4=BC=9A=E8=A2=AB=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flask-consul/units/jms/sync_jms.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/flask-consul/units/jms/sync_jms.py b/flask-consul/units/jms/sync_jms.py index fd0ae6b..0b3a038 100755 --- a/flask-consul/units/jms/sync_jms.py +++ b/flask-consul/units/jms/sync_jms.py @@ -2,6 +2,12 @@ import datetime,requests,json,traceback from units import consul_kv,consul_manager,myaes from units.config_log import * +def exist_ssh_port(port,protocols): + for protocol in protocols: + if protocol.get('name') == 'ssh': + return protocol.get('port', port) if protocol.get('port') != port else port + return port + #创建node def create_node(jms_url,headers,now,node_id,cloud,account): node_url = f"{jms_url}/api/v1/assets/nodes/{node_id}/children/" @@ -29,9 +35,9 @@ def update_jms_ecs(jms_ver,jms_url,headers,new_node_dict,node_id,cloud,account,e ecs_url = f"{jms_url}/api/v1/assets/assets/" reget_ecs_list = requests.request("GET", f'{ecs_url}?node={node_id}', headers=headers).json() try: - jms_ecs_dict = {i.get('ip',i.get('address','IPNOTFOUND')):{'name':i.get('hostname',i.get('name','NAMENOTFOUND')),'id':i['id'],'comment':i['comment'],'node':i['nodes_display'][0]} for i in reget_ecs_list} + jms_ecs_dict = {i.get('ip',i.get('address','IPNOTFOUND')):{'name':i.get('hostname',i.get('name','NAMENOTFOUND')),'id':i['id'],'protocols': i['protocols'],'comment':i['comment'],'node':i['nodes_display'][0]} for i in reget_ecs_list} except: - jms_ecs_dict = {i.get('ip',i.get('address','IPNOTFOUND')):{'name':i.get('hostname',i.get('name','NAMENOTFOUND')),'id':i['id'],'comment':i['comment'],'node':i['nodes'][0]} for i in reget_ecs_list} + jms_ecs_dict = {i.get('ip',i.get('address','IPNOTFOUND')):{'name':i.get('hostname',i.get('name','NAMENOTFOUND')),'id':i['id'],'protocols': i['protocols'],'comment':i['comment'],'node':i['nodes'][0]} for i in reget_ecs_list} ecs_list = consul_manager.get_instances(f'{cloud}_{account}_ecs')['instances'] ecs_ip_dict = {i['address']:i['meta'][0]['name'] for i in ecs_list} @@ -60,7 +66,8 @@ def update_jms_ecs(jms_ver,jms_url,headers,new_node_dict,node_id,cloud,account,e admin_user = custom_info[ostype][1] if jms_ver == 'V3': ecs_url = f"{jms_url}/api/v1/assets/hosts/" - proto,port = protocols[0].split('/') + proto,proto_port = protocols[0].split('/') + port = exist_ssh_port(proto_port, jms_ecs_dict.get(ip, {}).get("protocols", [])) payload = { "address": ip, "name": iname,