You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by st...@apache.org on 2012/04/03 17:30:11 UTC

svn commit: r1309063 - /incubator/tashi/trunk/src/tashi/agents/dhcpdns.py

Author: stroucki
Date: Tue Apr  3 17:30:10 2012
New Revision: 1309063

URL: http://svn.apache.org/viewvc?rev=1309063&view=rev
Log:
dhcpdns: add comments to some possible points of failure. pull out IP database initialisation from object constructor to perhaps reconstruct the db in the future.

Modified:
    incubator/tashi/trunk/src/tashi/agents/dhcpdns.py

Modified: incubator/tashi/trunk/src/tashi/agents/dhcpdns.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/agents/dhcpdns.py?rev=1309063&r1=1309062&r2=1309063&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/agents/dhcpdns.py (original)
+++ incubator/tashi/trunk/src/tashi/agents/dhcpdns.py Tue Apr  3 17:30:10 2012
@@ -55,15 +55,21 @@ class DhcpDns(InstanceHook):
 		self.ipMax = {}
 		self.currentIP = {}
 		self.usedIPs = {}
-		for k in self.ipRange:
-			ipRange = self.ipRange[k]
+
+		self.initIPs()
+
+	def initIPs(self):
+		self.usedIPs = {}
+		for network in self.ipRange:
+			ipRange = self.ipRange[network]
 			(min, max) = ipRange.split("-")	
 			min = min.strip()
 			max = max.strip()
 			ipNum = self.strToIp(min)
-			self.ipMin[k] = self.strToIp(min)
-			self.ipMax[k] = self.strToIp(max)
-			self.currentIP[k] = self.ipMin[k]
+			self.ipMin[network] = self.strToIp(min)
+			self.ipMax[network] = self.strToIp(max)
+			self.currentIP[network] = self.ipMin[network]
+
 		instances = self.client.getInstances()
 		for i in instances:
 			for nic in i.nics:
@@ -93,6 +99,9 @@ class DhcpDns(InstanceHook):
 		wrapToMinAlready = False
 		if (requestedIP <= self.ipMax[network] and requestedIP >= self.ipMin[network] and (requestedIP not in self.usedIPs)):
 			allocatedIP = requestedIP
+
+		# nic.ip will be updated later in preCreate if chosen
+		# ip not available
 		while (allocatedIP == None):
 			if (self.currentIP[network] > self.ipMax[network] and wrapToMinAlready):
 				raise UserWarning("No available IP addresses for network %d" % (network))
@@ -242,6 +251,9 @@ class DhcpDns(InstanceHook):
 			ip = nic.ip
 			try:
 				ipNum = self.strToIp(ip)
+				# XXXstroucki: if this fails with KeyError,
+				# we must have double-assigned the same IP
+				# address. How does this happen?
 				del self.usedIPs[ipNum]
 			except Exception, e:
 				self.log.exception("Failed to remove host %s, ip %s from pool of usedIPs" % (instance.name, ip))
@@ -254,6 +266,10 @@ class DhcpDns(InstanceHook):
 			except Exception, e:
 				self.log.exception("Failed to remove host %s from DHCP" % (instance.name))
 		try:
+			# XXXstroucki: this can fail if the resolver can't
+			# resolve the dns server name (line 190). Perhaps
+			# the hostname should be then pushed onto a list
+			# to try again next time.
 			self.removeDns(instance.name)
 		except Exception, e:
 			self.log.exception("Failed to remove host %s from DNS" % (instance.name))