def configure_network(hostname, interfaces):
    if os.path.exists(NETWORK_FILE):
        infile = open(NETWORK_FILE)
    else:
        infile = StringIO()

    update_files, remove_files = process_interface_files(infile, interfaces)

    # Generate new hostname file
    infile = StringIO(update_files.get(NETWORK_FILE, infile))

    data = get_hostname_file(infile, hostname)
    update_files[NETWORK_FILE] = 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, remove_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/init.d/network restart')
    p = subprocess.Popen(["/etc/init.d/network", "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 network: %d" % status)

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