fix ecs get ip bug
parent
39f2bab130
commit
7181e92f19
|
@ -149,14 +149,17 @@ def ecs(account,region,isextip=False):
|
|||
ecs_list = ecs.body.instances.to_map()['Instance']
|
||||
ecs_dict_temp = {i['InstanceId']:{
|
||||
'name':i['InstanceName'],'group':group_dict.get(i['ResourceGroupId'],'无'),'ostype':i['OSType'].lower(),'status':i['Status'],'region':region,
|
||||
'ip':i["InnerIpAddress"]["IpAddress"][0] if i["InnerIpAddress"]["IpAddress"] else i['NetworkInterfaces']['NetworkInterface'][0]['PrimaryIpAddress'],
|
||||
'ip':i["InnerIpAddress"]["IpAddress"][0] if i["InnerIpAddress"]["IpAddress"] else i['NetworkInterfaces']['NetworkInterface'][0].get('PrimaryIpAddress','NoneInnerIp'),
|
||||
'cpu':f"{i['Cpu']}核",'mem':f"{str(round(i['Memory']/1024,1)).rstrip('.0')}GB",'exp':i['ExpiredTime'].split('T')[0],'ecstag': i.get('Tags',{}).get('Tag',[])
|
||||
}for i in ecs_list}
|
||||
|
||||
if isextip:
|
||||
for i in ecs_list:
|
||||
try:
|
||||
ecs_dict_temp[i['InstanceId']]['ip'] = i['PublicIpAddress']['IpAddress'][0] if i['PublicIpAddress']['IpAddress'] else i["EipAddress"]["IpAddress"]
|
||||
if i['PublicIpAddress']['IpAddress']:
|
||||
ecs_dict_temp[i['InstanceId']]['ip'] = i['PublicIpAddress']['IpAddress'][0]
|
||||
elif i["EipAddress"]["IpAddress"] != '':
|
||||
ecs_dict_temp[i['InstanceId']]['ip'] = i["EipAddress"]["IpAddress"]
|
||||
except:
|
||||
pass
|
||||
ecs_dict.update(ecs_dict_temp)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import datetime,requests,json
|
||||
import datetime,requests,json,traceback
|
||||
from units import consul_kv,consul_manager,myaes
|
||||
from units.config_log import *
|
||||
|
||||
|
@ -68,10 +68,10 @@ def update_jms_ecs(jms_url,headers,new_node_dict,node_id,cloud,account,ecs_info,
|
|||
jms_group = '无' if jms_ecs_dict[ip]['node'].split('/')[-1] == '未分组' else jms_ecs_dict[ip]['node'].split('/')[-1]
|
||||
if jms_ecs_dict[ip]['name'] != iname or jms_group != v['ent']:
|
||||
response = requests.request("PUT", f"{ecs_url}{jms_ecs_dict[ip]['id']}/", headers=headers, data = json.dumps(payload))
|
||||
logger.info(f" 【JMS】update:主机名:{response.json()['hostname']},{response.status_code}")
|
||||
logger.info(f" 【JMS】update:主机名:{response.json().get('hostname',response.json())},{response.status_code}")
|
||||
else:
|
||||
response = requests.request("POST", ecs_url, headers=headers, data = json.dumps(payload))
|
||||
logger.info(f" 【JMS】add:主机名:{iname} {ip}【{response.json()['hostname']},{response.status_code}】")
|
||||
logger.info(f" 【JMS】add:主机名:{iname} {ip}【{response.json().get('hostname',response.json())},{response.status_code}】")
|
||||
except Exception as e:
|
||||
logger.error(f'【update_jms ERROR】{e}\n{traceback.format_exc()}')
|
||||
logger.error(f'{response.json()}')
|
||||
|
|
|
@ -46,7 +46,7 @@ Object.keys(filters).forEach(key => {
|
|||
})
|
||||
|
||||
Vue.config.productionTip = false
|
||||
Vue.prototype.VER = 'v0.12.3'
|
||||
Vue.prototype.VER = 'v0.12.4'
|
||||
|
||||
new Vue({
|
||||
el: '#app',
|
||||
|
|
Loading…
Reference in New Issue