Switch to using DNS for host->ip resolution as this is more provider independent, use .format for string formatting

This commit is contained in:
James Page 2012-10-04 10:09:59 +01:00
parent 407d54f91d
commit 3d5506ce5a
2 changed files with 14 additions and 5 deletions

View File

@ -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

View File

@ -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()