class HostIPContext(context.OSContextGenerator):
def __call__(self):
ctxt = {}
# Use the address used in the cloud-compute relation in templates for
# this host
host_ip = get_relation_ip('cloud-compute', cidr_network=config('os-internal-network'))
if host_ip:
# NOTE: do not format this even for ipv6 (see bug 1499656) ctxt['host_ip'] = host_ip
return ctxt
this template item should always be resolved to an IP address; in the event that the provider does not support network binding ('cloud-compute' relation) or the os-internal-network configuration option is not provided (cidr_network), the function should just be doing:
Groking the code:
class HostIPContext( context. OSContextGenera tor): ip('cloud- compute' ,
cidr_ network= config( 'os-internal- network' ))
def __call__(self):
ctxt = {}
# Use the address used in the cloud-compute relation in templates for
# this host
host_ip = get_relation_
if host_ip:
ctxt[ 'host_ip' ] = host_ip
# NOTE: do not format this even for ipv6 (see bug 1499656)
return ctxt
this template item should always be resolved to an IP address; in the event that the provider does not support network binding ('cloud-compute' relation) or the os-internal-network configuration option is not provided (cidr_network), the function should just be doing:
address = get_host_ ip(unit_ get('private- address' ))