diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDhcp.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDhcp.py index 3f102e6e28d..d97c04be723 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDhcp.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDhcp.py @@ -17,6 +17,7 @@ import CsHelper import logging from netaddr import * +from random import randint from CsGuestNetwork import CsGuestNetwork from cs.CsDatabag import CsDataBag from cs.CsFile import CsFile @@ -44,7 +45,7 @@ class CsDhcp(CsDataBag): continue self.add(self.dbag[item]) self.write_hosts() - + if self.cloud.is_changed(): self.delete_leases() @@ -59,23 +60,24 @@ class CsDhcp(CsDataBag): def configure_server(self): # self.conf.addeq("dhcp-hostsfile=%s" % DHCP_HOSTS) + idx = 0 for i in self.devinfo: if not i['dnsmasq']: continue device = i['dev'] ip = i['ip'].split('/')[0] - sline = "dhcp-range=interface:%s,set:interface" % (device) - line = "dhcp-range=interface:%s,set:interface-%s,%s,static" % (device, device, ip) + sline = "dhcp-range=interface:%s,set:interface-%s-%s" % (device, device, idx) + line = "dhcp-range=interface:%s,set:interface-%s-%s,%s,static" % (device, device, idx, ip) self.conf.search(sline, line) gn = CsGuestNetwork(device, self.config) - sline = "dhcp-option=tag:interface-%s,15" % device - line = "dhcp-option=tag:interface-%s,15,%s" % (device, gn.get_domain()) + sline = "dhcp-option=tag:interface-%s-%s,15" % (device, idx) + line = "dhcp-option=tag:interface-%s-%s,15,%s" % (device, idx, gn.get_domain()) self.conf.search(sline, line) # DNS search order if gn.get_dns() and device: - sline = "dhcp-option=tag:interface-%s,6" % device + sline = "dhcp-option=tag:interface-%s-%s,6" % (device, idx) dns_list = [x for x in gn.get_dns() if x is not None] - line = "dhcp-option=tag:interface-%s,6,%s" % (device, ','.join(dns_list)) + line = "dhcp-option=tag:interface-%s-%s,6,%s" % (device, idx, ','.join(dns_list)) self.conf.search(sline, line) # Gateway gateway = '' @@ -83,8 +85,8 @@ class CsDhcp(CsDataBag): gateway = gn.get_gateway() else: gateway = i['gateway'] - sline = "dhcp-option=tag:interface-%s,3," % device - line = "dhcp-option=tag:interface-%s,3,%s" % (device, gateway) + sline = "dhcp-option=tag:interface-%s-%s,3," % (device, idx) + line = "dhcp-option=tag:interface-%s-%s,3,%s" % (device, idx, gateway) self.conf.search(sline, line) # Netmask netmask = '' @@ -92,9 +94,10 @@ class CsDhcp(CsDataBag): netmask = gn.get_netmask() else: netmask = self.config.address().get_guest_netmask() - sline = "dhcp-option=tag:interface-%s,1," % device - line = "dhcp-option=tag:interface-%s,1,%s" % (device, netmask) + sline = "dhcp-option=tag:interface-%s-%s,1," % (device, idx) + line = "dhcp-option=tag:interface-%s-%s,1,%s" % (device, idx, netmask) self.conf.search(sline, line) + idx += 1 def delete_leases(self): try: @@ -104,7 +107,7 @@ class CsDhcp(CsDataBag): def preseed(self): self.add_host("127.0.0.1", "localhost") - self.add_host("::1", "localhost ip6-localhost ip6-loopback") + self.add_host("::1", "localhost ip6-localhost ip6-loopback") self.add_host("ff02::1", "ip6-allnodes") self.add_host("ff02::2", "ip6-allrouters") if self.config.is_vpc(): @@ -125,9 +128,15 @@ class CsDhcp(CsDataBag): def add(self, entry): self.add_host(entry['ipv4_adress'], entry['host_name']) - self.cloud.add("%s,%s,%s,infinite" % (entry['mac_address'], - entry['ipv4_adress'], - entry['host_name'])) + + # lease time boils down to once a month + # with a splay of 60 hours to prevent storms + lease = randint(700, 760) + self.cloud.add("%s,%s,%s,%sh" % (entry['mac_address'], + entry['ipv4_adress'], + entry['host_name'], + lease + )) i = IPAddress(entry['ipv4_adress']) # Calculate the device for v in self.devinfo: