Switch to using DNS for host->ip resolution as this is more provider independent, use .format for string formatting
This commit is contained in:
parent
407d54f91d
commit
3d5506ce5a
@ -69,15 +69,15 @@ def config_changed():
|
||||
|
||||
def get_mon_hosts():
|
||||
hosts = []
|
||||
hosts.append(socket.gethostbyname(utils.unit_get('private-address'))
|
||||
+ ':6789')
|
||||
hosts.append('{}:6789'.format(utils.get_host_ip()))
|
||||
|
||||
for relid in utils.relation_ids('mon'):
|
||||
for unit in utils.relation_list(relid):
|
||||
hosts.append(
|
||||
socket.gethostbyname(utils.relation_get('private-address',
|
||||
unit, relid))
|
||||
+ ':6789')
|
||||
'{}:6789'.format(utils.get_host_ip(
|
||||
utils.relation_get('private-address',
|
||||
unit, relid)))
|
||||
)
|
||||
|
||||
hosts.sort()
|
||||
return hosts
|
||||
|
@ -140,3 +140,12 @@ def config_get(attribute):
|
||||
|
||||
def get_unit_hostname():
|
||||
return socket.gethostname()
|
||||
|
||||
|
||||
def get_host_ip(hostname=unit_get('private-address')):
|
||||
cmd = [
|
||||
'dig',
|
||||
'+short',
|
||||
hostname
|
||||
]
|
||||
return subprocess.check_call(cmd).strip()
|
||||
|
Loading…
Reference in New Issue
Block a user