@cached
def get_host_ip(hostname=None):
if config('prefer-ipv6'):
return get_ipv6_addr()[0]
hostname = hostname or unit_get('private-address')
try:
# Test to see if already an IPv4 address socket.inet_aton(hostname)
return hostname
except socket.error:
return socket.gethostbyname(hostname)
So, this works just fine:
@cached ip(hostname= None): 'prefer- ipv6'):
def get_host_
if config(
return get_ipv6_addr()[0]
hostname = hostname or unit_get( 'private- address' )
socket. inet_aton( hostname) gethostbyname( hostname)
try:
# Test to see if already an IPv4 address
return hostname
except socket.error:
return socket.