| 198 | logging.debug("Hosts file unchanged") |
| 199 | |
| 200 | def add(self, entry): |
| 201 | self.add_host(entry['ipv4_address'], entry['host_name']) |
| 202 | # Lease time set to "infinite" since we properly control all DHCP/DNS config via CloudStack. |
| 203 | # Infinite time helps avoid some edge cases which could cause DHCPNAK being sent to VMs since |
| 204 | # (RHEL) system lose routes when they receive DHCPNAK. |
| 205 | # When VM is expunged, its active lease and DHCP/DNS config is properly removed from related files in VR, |
| 206 | # so the infinite duration of lease does not cause any issues or garbage. |
| 207 | lease = 'infinite' |
| 208 | |
| 209 | if entry['default_entry']: |
| 210 | self.dhcp_hosts.add("%s,%s,%s,%s" % (entry['mac_address'], |
| 211 | entry['ipv4_address'], |
| 212 | entry['host_name'], |
| 213 | lease)) |
| 214 | self.dhcp_leases.search(entry['mac_address'], "0 %s %s %s *" % (entry['mac_address'], |
| 215 | entry['ipv4_address'], |
| 216 | entry['host_name'])) |
| 217 | else: |
| 218 | tag = entry['ipv4_address'].replace(".", "_") |
| 219 | self.dhcp_hosts.add("%s,set:%s,%s,%s,%s" % (entry['mac_address'], |
| 220 | tag, |
| 221 | entry['ipv4_address'], |
| 222 | entry['host_name'], |
| 223 | lease)) |
| 224 | self.dhcp_opts.add("%s,%s" % (tag, 3)) |
| 225 | self.dhcp_opts.add("%s,%s" % (tag, 6)) |
| 226 | self.dhcp_opts.add("%s,%s" % (tag, 15)) |
| 227 | self.dhcp_leases.search(entry['mac_address'], "0 %s %s %s *" % (entry['mac_address'], |
| 228 | entry['ipv4_address'], |
| 229 | entry['host_name'])) |
| 230 | |
| 231 | i = IPAddress(entry['ipv4_address']) |
| 232 | # Calculate the device |
| 233 | for v in self.devinfo: |
| 234 | if i > v['network'].network and v['network'].broadcast and i < v['network'].broadcast: |
| 235 | v['dnsmasq'] = True |
| 236 | # Virtual Router |
| 237 | v['gateway'] = entry['default_gateway'] |
| 238 | |
| 239 | def add_host(self, ip, hosts): |
| 240 | self.hosts[ip] = hosts |