From df1eaace6a0eb7bc6bd052f6b3cc9ef04b5edc6b Mon Sep 17 00:00:00 2001 From: starsliao Date: Wed, 4 Jan 2023 15:39:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=BD=8E=E7=89=88=E6=9C=ACju?= =?UTF-8?q?mpserver=20fix=20#47?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flask-consul/units/jms/sync_jms.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flask-consul/units/jms/sync_jms.py b/flask-consul/units/jms/sync_jms.py index 0eb8ace..a043865 100755 --- a/flask-consul/units/jms/sync_jms.py +++ b/flask-consul/units/jms/sync_jms.py @@ -26,7 +26,11 @@ def update_jms_ecs(jms_url,headers,new_node_dict,node_id,cloud,account,ecs_info, #比较云主机与JMS中对应node的主机列表,删除jms中多余的主机 ecs_url = f"{jms_url}/api/v1/assets/assets/" reget_ecs_list = requests.request("GET", f'{ecs_url}?node={node_id}', headers=headers).json() - jms_ecs_dict = {i['ip']:{'name':i['hostname'],'id':i['id'],'comment':i['comment'],'node':i['nodes_display'][0]} for i in reget_ecs_list} + try: + jms_ecs_dict = {i['ip']:{'name':i['hostname'],'id':i['id'],'comment':i['comment'],'node':i['nodes_display'][0]} for i in reget_ecs_list} + except: + jms_ecs_dict = {i['ip']:{'name':i['hostname'],'id':i['id'],'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} ecs_dict = {i['ID']:{'name':i['meta'][0]['name'],'ip':i['address'],'ent':i['meta'][0]['group'],'ostype':i['meta'][0]['os'],'region':i['meta'][0]['region'],'vendor':i['meta'][0]['vendor']} for i in ecs_list}