#NEWLINE# def _output_hosts_file( self ) : #NEWLINE# #INDENT# "Writes a dnsmasq compatible dhcp hosts file.\n\n        The generated file is sent to the --dhcp-hostsfile option of dnsmasq,\n        and lists the hosts on the network which should receive a dhcp lease.\n        Each line in this file is in the form::\n\n            'mac_address,FQDN,ip_address'\n\n        IMPORTANT NOTE: a dnsmasq instance does not resolve hosts defined in\n        this file if it did not give a lease to a host listed in it (e.g.:\n        multiple dnsmasq instances on the same network if this network is on\n        multiple network nodes). This file is only defining hosts which\n        should receive a dhcp lease, the hosts resolution in itself is\n        defined by the `_output_addn_hosts_file` method.\n        " #NEWLINE# buf = six . StringIO ( ) #NEWLINE# filename = self . get_conf_file_name ( 'host' ) #NEWLINE# LOG . debug ( 'Building host file: %s' , filename ) #NEWLINE# dhcp_enabled_subnet_ids = [ s . id for s in self . network . subnets if s . enable_dhcp ] #NEWLINE# for host_tuple in self . _iter_hosts ( ) : #NEWLINE# #INDENT# ( port , alloc , hostname , name , no_dhcp , no_opts ) = host_tuple #NEWLINE# if no_dhcp : #NEWLINE# #INDENT# if ( ( not no_opts ) and self . _get_port_extra_dhcp_opts ( port ) ) : #NEWLINE# #INDENT# buf . write ( ( '%s,%s%s\n' % ( port . mac_address , 'set:' , port . id ) ) ) #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# if ( name . subnet_id not in dhcp_enabled_subnet_ids ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ip_address = self . _format_address_for_dnsmasq ( alloc . ip_address ) #NEWLINE# if self . _get_port_extra_dhcp_opts ( port ) : #NEWLINE# #INDENT# client_id = self . _get_client_id ( port ) #NEWLINE# if ( client_id and ( len ( port . extra_dhcp_opts ) > 1 ) ) : #NEWLINE# #INDENT# buf . write ( ( '%s,%s%s,%s,%s,%s%s\n' % ( port . mac_address , self . _ID , client_id , name , ip_address , 'set:' , port . id ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( client_id and ( len ( port . extra_dhcp_opts ) == 1 ) ) : #NEWLINE# #INDENT# buf . write ( ( '%s,%s%s,%s,%s\n' % ( port . mac_address , self . _ID , client_id , name , ip_address ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# buf . write ( ( '%s,%s,%s,%s%s\n' % ( port . mac_address , name , ip_address , 'set:' , port . id ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# buf . write ( ( '%s,%s,%s\n' % ( port . mac_address , name , ip_address ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# common_utils . replace_file ( filename , buf . getvalue ( ) ) #NEWLINE# LOG . debug ( 'Done building host file %s' , filename ) #NEWLINE# return filename