def _confd_net_file(interfaces):
    """Given the interfaces creates the network configuration content.

    This will generate the /etc/conf.d/net configuration file for a Gentoo
    server running this agent.

    """

    ifaces = set()

    lines = []
    lines.append(_header())
    lines.append("")
    if commands.utils.is_system_command("ip"):
        lines.append('modules="iproute2"')
    else:
        lines.append('modules="ifconfig"')
    lines.append("")
    lines.append("")

    for name, interface in interfaces.iteritems():
        if interface['label']:
            lines.append("# Label %s" % interface['label'])
        lines.append("config_{0}=\"".format(name))
        lines.extend(["  {0}/{1}".format(ip['address'],
                        commands.network.NETMASK_TO_PREFIXLEN[ip['netmask']]
                    ) for ip in interface['ip4s'] ])
        lines.extend([ "  {0}/{1}".format(ip['address'], ip['prefixlen']
                    ) for ip in interface['ip6s'] ])
        lines.append("\"")
        lines.append("")

        lines.append("routes_{0}=\"".format(name))
        lines.extend([ "  {0}/{1} via {2}".format(route['network'],
                        commands.network.NETMASK_TO_PREFIXLEN[route['netmask']],
                        route['gateway']
                    ) for route in interface['routes'] if not
                    route['network'] == '0.0.0.0' and not
                    route['netmask'] == '0.0.0.0' and
                    'gateway4' in interface and not
                    route['gateway'] == interface['gateway4']])
        if 'gateway4' in interface and interface['gateway4']:
            lines.append("  default via {0}".format(interface['gateway4']))
        if 'gateway6' in interface and interface['gateway6']:
            lines.append("  default via {0}".format(interface['gateway6']))
        lines.append("\"")
        lines.append("")

        dns = interface['dns']
        if dns:
            lines.append('dns_servers_{0}="{1}"\n'.format(name,
                                                          '\n'.join(dns)))
            lines.append("")

        ifaces.add(name)

    return "\n".join(lines), ifaces
dataset/ETHPy150Open rackerlabs/openstack-guest-agents-unix/commands/gentoo/network.py/_confd_net_file/original