def _create_rcconf_file(infile, interfaces, hostname):

    ipv6_interfaces = []
    static_route_entries = []

    outfile = StringIO()

    for line in infile:
        line = line.strip()
        if line.startswith("ifconfig") or \
                line.startswith("defaultrouter") or \
                line.startswith("ipv6_ifconfig") or \
                line.startswith("ipv6_defaultrouter") or \
                line.startswith("ipv6_enable") or \
                line.startswith("static_routes") or \
                line.startswith("route_") or \
                line.startswith("dhcpd_") or \
                line.startswith("hostname"):
            continue
        print >> outfile, line

    print >> outfile, 'dhcpd_enable="NO"'
    print >> outfile, 'hostname=%s' % hostname

    gateway4, gateway6 = commands.network.get_gateways(interfaces)

    ifnames = interfaces.keys()
    ifnames.sort()
    for ifname_prefix in ifnames:
        interface = interfaces[ifname_prefix]

        label = interface.get('label')

        ip4s = interface['ip4s']
        ip6s = interface['ip6s']

        if ip6s:
            ipv6_interfaces.append(ifname_prefix)

        ifname_suffix_num = 0

        for ip4, ip6 in map(None, ip4s, ip6s):
            if ifname_suffix_num:
                ifname = "%s_alias%d" % (ifname_prefix, ifname_suffix_num - 1)
            else:
                ifname = ifname_prefix
                if label:
                    print >>outfile, '# Label %s' % label

            if ip4:
                if ifname_suffix_num:
                    # XXX -- Known bug here.  If we're adding an alias
                    # that is on the same network as another address already
                    # configured, the netmask here should be 255.255.255.255
                    print >> outfile, 'ifconfig_%s="%s netmask %s"' % \
                            (ifname, ip4['address'], ip4['netmask'])
                else:
                    print >> outfile, 'ifconfig_%s="%s netmask %s up"' % \
                            (ifname, ip4['address'], ip4['netmask'])

            if ip6:
                print >> outfile, 'ipv6_ifconfig_%s="%s/%s"' % \
                        (ifname, ip6['address'], ip6['prefixlen'])

            ifname_suffix_num += 1

        for route in interface['routes']:
            if route['network'] == '0.0.0.0' and \
                    route['netmask'] == '0.0.0.0' and \
                    route['gateway'] == gateway4:
                continue
            if ':' in route['network']:
                # ipv6
                fmt = '-net %(network)s/%(netmask)s %(gateway)s'
            else:
                fmt = '-net %(network)s -netmask %(netmask)s %(gateway)s'

            static_route_entries.append(fmt % route)

    if static_route_entries:
        names = []
        for i, line in enumerate(static_route_entries):
            name = 'lan%d' % i
            names.append(name)
            print >> outfile, 'route_%s="%s"' % (name, line)

        print >> outfile, 'static_routes="%s"' % ' '.join(names)

    if ipv6_interfaces:
        print >> outfile, 'ipv6_enable="YES"'
        print >> outfile, 'ipv6_network_interfaces="%s"' % \
            ','.join(ipv6_interfaces)

    if gateway4:
        print >> outfile, 'defaultrouter="%s"' % gateway4

    if gateway6:
        print >> outfile, 'ipv6_defaultrouter="%s%%%s"' % \
                (gateway6, 'xn0')

    outfile.seek(0)
    return outfile.read()
Return new rc.conf, merging in 'infile'
dataset/ETHPy150Open rackerlabs/openstack-guest-agents-unix/commands/freebsd/network.py/_create_rcconf_file