[%
# vi: ft=tt2

# Returns the interface name of a given IP address.
#
# @param argv.host      The current host for IP interface name mapping.
# @param argv.ip        The IP address to map.
# @return out           The interface name of the given IP.

out = '';
FOREACH key IN hosts.${argv.host}.keys;
  IF hosts.${argv.host}.${key}.ip.defined &&
     hosts.${argv.host}.${key}.ip == argv.ip;
    out = "$key";
    RETURN;
  ELSIF hosts.${argv.host}.${key}.shared_ip.defined &&
        hosts.${argv.host}.${key}.shared_ip.size > 0;
    FOREACH shared_ip IN hosts.${argv.host}.${key}.shared_ip;
      IF shared_ip == argv.ip;
        out = "$key:$loop.index";
        RETURN;
      END;
    END;
  END;
END;

-%]
