'Writes a dnsmasq compatible dhcp hosts file.
The generated file is sent to the --dhcp-hostsfile option of dnsmasq,
and lists the hosts on the network which should receive a dhcp lease.
Each line in this file is in the form::
\'mac_address,FQDN,ip_address\'
IMPORTANT NOTE: a dnsmasq instance does not resolve hosts defined in
this file if it did not give a lease to a host listed in it (e.g.:
multiple dnsmasq instances on the same network if this network is on
multiple network nodes). This file is only defining hosts which
should receive a dhcp lease, the hosts resolution in itself is
defined by the `_output_addn_hosts_file` method.'

def _output_hosts_file(self):

    buf = six.StringIO()
    filename = self.get_conf_file_name('host')
    LOG.debug('Building    host    file:    %s', filename)
    dhcp_enabled_subnet_ids = [s.id for s in self._get_all_subnets(self.network) if s.enable_dhcp]
    for host_tuple in self._iter_hosts():
        (port, alloc, hostname, name, no_dhcp, no_opts) = host_tuple
        if no_dhcp:
            if ((not no_opts) and self._get_port_extra_dhcp_opts(port)):
                buf.write(('%s,%s%s\n' % (port.mac_address, 'set:', port.id)))
            continue
        if (alloc.subnet_id not in dhcp_enabled_subnet_ids):
            continue
        ip_address = self._format_address_for_dnsmasq(alloc.ip_address)
        if self._get_port_extra_dhcp_opts(port):
            client_id = self._get_client_id(port)
            if (client_id and (len(port.extra_dhcp_opts) > 1)):
                buf.write(('%s,%s%s,%s,%s,%s%s\n' % (port.mac_address, self._ID, client_id, name, ip_address, 'set:', port.id)))
            elif (client_id and (len(port.extra_dhcp_opts) == 1)):
                buf.write(('%s,%s%s,%s,%s\n' % (port.mac_address, self._ID, client_id, name, ip_address)))
            else:
                buf.write(('%s,%s,%s,%s%s\n' % (port.mac_address, name, ip_address, 'set:', port.id)))
        else:
            buf.write(('%s,%s,%s\n' % (port.mac_address, name, ip_address)))
    file_utils.replace_file(filename, buf.getvalue())
    LOG.debug('Done    building    host    file    %s', filename)
    return filename
