cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sw...@apache.org
Subject [05/15] git commit: updated refs/heads/master to e4ba640
Date Tue, 28 Jun 2016 15:28:39 GMT
VR CsDhcp: allow multiple ranges & finite lease time (fixes CLOUDSTACK-8303)


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/87537904
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/87537904
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/87537904

Branch: refs/heads/master
Commit: 875379042eeae60635b326114a3a3d34ac529cd1
Parents: 2790d7a
Author: Ronald van Zantvoort <ronald@pcextreme.nl>
Authored: Fri May 13 17:21:18 2016 +0200
Committer: Wido den Hollander <wido@widodh.nl>
Committed: Tue Jun 7 13:03:09 2016 +0200

----------------------------------------------------------------------
 .../debian/config/opt/cloud/bin/cs/CsDhcp.py    | 39 ++++++++++++--------
 1 file changed, 24 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/87537904/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDhcp.py
----------------------------------------------------------------------
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 3f102e6..d97c04b 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:


Mime
View raw message