Comment 9 for bug 1721368

Revision history for this message
James Page (james-page) wrote : Re: Sets my_ip to hostname, not IP address

Groking the code:

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:

   address = get_host_ip(unit_get('private-address'))