def get_db_host():
# first try to look for a loopback alias addr
loopback_addr = get_lo_alias_addr()
if loopback_addr:
return loopback_addr
# if we did not find any IP on the loopback if, find the
# interface of the default gateway and use that.
try:
default_if = netifaces.gateways().get('default', {}).values()[0][1]
if_addr = netifaces.ifaddresses(default_if)[netifaces.AF_INET][0].get(
'addr')
return if_addr
except KeyError:
raise Exception('Cannot find DB address for the current host')
评论列表
文章目录