def configure_network(hostname, interfaces):
    update_files = {}

    # Unset LD_LIBRARY_PATH
    env = os.environ.copy()
    if 'LD_LIBRARY_PATH' in env:
        del env['LD_LIBRARY_PATH']

    # Generate new /etc/rc.conf
    data = _get_file_data(interfaces, hostname)
    update_files[RCCONF_FILE] = data

    # Generate new /etc/resolv.conf file
    # Uses resolvconf utility if present else creates /etc/resolv.conf
    nameservers = fetch_all_from_xendict(interfaces, 'dns')
    if not commands.network.update_resolvconf(nameservers):
        filepath, data = commands.network.get_resolv_conf(interfaces)
        if data:
            update_files[filepath] = data

    # Generate new /etc/hosts file
    filepath, data = commands.network.get_etc_hosts(interfaces, hostname)
    update_files[filepath] = data

    # Write out new files
    commands.network.update_files(update_files)

    pipe = subprocess.PIPE

    # Set hostname
    try:
        commands.network.sethostname(hostname)
    except Exception, e:
        logging.error("Couldn't sethostname(): %s" % str(e))
        return (500, "Couldn't set hostname: %s" % str(e))

    # Restart network
    logging.debug('executing /etc/rc.d/netif restart')
    p = subprocess.Popen(["/bin/sh", "/etc/rc.d/netif", "restart"],
            stdin=pipe, stdout=pipe, stderr=pipe, env=env)
    logging.debug('waiting on pid %d' % p.pid)
    status = os.waitpid(p.pid, 0)[1]
    logging.debug('status = %d' % status)

    if status != 0:
        return (500, "Couldn't restart IPv4 networking: %d" % status)

    # Restart network
    if os.path.exists("/etc/rc.d/network_ipv6"):
        logging.debug('executing /etc/rc.d/network_ipv6 restart')
        p = subprocess.Popen(["/etc/rc.d/network_ipv6", "restart"],
                stdin=pipe, stdout=pipe, stderr=pipe, env={})
        logging.debug('waiting on pid %d' % p.pid)
        status = os.waitpid(p.pid, 0)[1]
        logging.debug('status = %d' % status)

        if status != 0:
            return (500, "Couldn't restart IPv6 networking: %d" % status)

    # Restart routing
    logging.debug('executing /etc/rc.d/routing restart')
    p = subprocess.Popen(["/bin/sh", "/etc/rc.d/routing", "restart"],
            stdin=pipe, stdout=pipe, stderr=pipe, env=env)
    logging.debug('waiting on pid %d' % p.pid)
    status = os.waitpid(p.pid, 0)[1]
    logging.debug('status = %d' % status)

    #if status != 0:
    #    return (500, "Couldn't restart network routing: %d" % status)

    return (0, "")
dataset/ETHPy150Open rackerlabs/openstack-guest-agents-unix/commands/freebsd/network.py/configure_network/original