'Extract the container IP from a docker inspect object, or the kubelet API.'

def _get_host_address(self, state, c_id, tpl_var):

    c_inspect = state.inspect_container(c_id)
    (c_id, c_img) = (c_inspect.get('Id', ''), c_inspect.get('Config', {}).get('Image', ''))
    networks = (c_inspect.get('NetworkSettings', {}).get('Networks') or {})
    ip_dict = {}
    for (net_name, net_desc) in networks.iteritems():
        ip = net_desc.get('IPAddress')
        if ip:
            ip_dict[net_name] = ip
    ip_addr = self._extract_ip_from_networks(ip_dict, tpl_var)
    if ip_addr:
        return ip_addr
    log.debug(('No    IP    address    was    found    in    container    %s    (%s)    networks,    trying    with    the    IPAddress    field' % (c_id[:12], c_img)))
    ip_addr = c_inspect.get('NetworkSettings', {}).get('IPAddress')
    if ip_addr:
        return ip_addr
    if Platform.is_k8s():
        log.debug(("Couldn't    find    the    IP    address    for    container    %s    (%s),    using    the    kubernetes    way." % (c_id[:12], c_img)))
        pod_ip = state.get_kube_config(c_id, 'status').get('podIP')
        if pod_ip:
            return pod_ip
    if Platform.is_rancher():
        log.debug(('No    IP    address    was    found    in    container    %s    (%s)    trying    with    the    Rancher    label' % (c_id[:12], c_img)))
        ip_addr = c_inspect.get('Config', {}).get('Labels', {}).get(RANCHER_CONTAINER_IP)
        if ip_addr:
            return ip_addr.split('/')[0]
    log.error(('No    IP    address    was    found    for    container    %s    (%s)' % (c_id[:12], c_img)))
    return None
