incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mry...@apache.org
Subject svn commit: r769864 - in /incubator/tashi/trunk: etc/TashiDefaults.cfg src/tashi/agents/dhcpdns.py
Date Wed, 29 Apr 2009 18:29:42 GMT
Author: mryan3
Date: Wed Apr 29 18:29:41 2009
New Revision: 769864

URL: http://svn.apache.org/viewvc?rev=769864&view=rev
Log:
Added support in the dhcp/dns plugin for partitioning multiple networks
Added support in the dhcp/dhs plugin for more specific IP ranges


Modified:
    incubator/tashi/trunk/etc/TashiDefaults.cfg
    incubator/tashi/trunk/src/tashi/agents/dhcpdns.py

Modified: incubator/tashi/trunk/etc/TashiDefaults.cfg
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/etc/TashiDefaults.cfg?rev=769864&r1=769863&r2=769864&view=diff
==============================================================================
--- incubator/tashi/trunk/etc/TashiDefaults.cfg (original)
+++ incubator/tashi/trunk/etc/TashiDefaults.cfg Wed Apr 29 18:29:41 2009
@@ -106,7 +106,7 @@
 dhcpServer = 1.2.3.4
 dhcpKeyName = OMAPI
 dhcpSecretKey = ABcdEf12GhIJKLmnOpQrsT==
-ipRange = 172.16.128.0/17
+ipRange1 = 172.16.128.2-172.16.255.254
 reverseDns = True
 
 # Logging stuff

Modified: incubator/tashi/trunk/src/tashi/agents/dhcpdns.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/agents/dhcpdns.py?rev=769864&r1=769863&r2=769864&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/agents/dhcpdns.py (original)
+++ incubator/tashi/trunk/src/tashi/agents/dhcpdns.py Wed Apr 29 18:29:41 2009
@@ -31,16 +31,34 @@
 		self.dhcpServer = self.config.get('DhcpDns', 'dhcpServer')
 		self.dhcpKeyName = self.config.get('DhcpDns', 'dhcpKeyName')
 		self.dhcpSecretKey = self.config.get('DhcpDns', 'dhcpSecretKey')
-		self.ipRange = self.config.get('DhcpDns', 'ipRange')
+		items = self.config.items('DhcpDns')
+		items.sort()
+		self.ipRange = {}
+		for item in items:
+			(name, value) = item
+			name = name.lower()
+			if (name.startswith('iprange')):
+				network = name[7:]
+				try:
+					network = int(network)
+				except:
+					continue
+				self.ipRange[network] = value	
 		self.reverseDns = boolean(self.config.get('DhcpDns', 'reverseDns'))
 		self.log = logging.getLogger(__file__)
-		(ip, bits) = self.ipRange.split("/")
-		bits = int(bits)
-		ipNum = self.strToIp(ip)
-		self.ipMin = ((ipNum>>(32-bits))<<(32-bits)) + 2
-		self.ipMax = self.ipMin + (1<<(32-bits)) - 3
+		self.ipMin = {}
+		self.ipMax = {}
+		self.currentIP = {}
 		self.usedIPs = {}
-		self.currentIP = self.ipMin
+		for k in self.ipRange:
+			ipRange = self.ipRange[k]
+			(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]
 		instances = self.client.getInstances()
 		for i in instances:
 			try:
@@ -58,15 +76,15 @@
 	def ipToStr(self, ip):
 		return "%d.%d.%d.%d" % (ip>>24, (ip>>16)%256, (ip>>8)%256, ip%256)
 	
-	def allocateIP(self):
-		self.currentIP = self.currentIP + 1
-		while (self.currentIP in self.usedIPs or self.currentIP > self.ipMax):
-			if (self.currentIP > self.ipMax):
-				self.currentIP = self.ipMin
+	def allocateIP(self, network):
+		while (self.currentIP[network] in self.usedIPs or self.currentIP[network] > self.ipMax[network]):
+			if (self.currentIP[network] > self.ipMax[network]):
+				self.currentIP[network] = self.ipMin[network]
 			else:
-				self.currentIP = self.currentIP + 1
-		ipString = self.ipToStr(self.currentIP)
-		self.usedIPs[self.currentIP] = ipString
+				self.currentIP[network] = self.currentIP[network] + 1
+		ipString = self.ipToStr(self.currentIP[network])
+		self.usedIPs[self.currentIP[network]] = ipString
+		self.currentIP[network] = self.currentIP[network] + 1
 		return ipString
 	
 	def addDhcp(self, name, ipaddr, hwaddr):
@@ -141,7 +159,10 @@
 		stdout.close()
 	
 	def preCreate(self, instance):
-		ip = self.allocateIP()
+		if (len(instance.nics) < 1):
+			return
+		network = instance.nics[0].network
+		ip = self.allocateIP(network)
 		self.log.info("Adding %s:{%s->%s, %s->%s} to DHCP/DNS" % (instance.name, instance.nics[0].mac,
ip, instance.name, ip))
 		try:
 			self.addDhcp(instance.name, ip, instance.nics[0].mac)
@@ -150,6 +171,8 @@
 			self.log.exception("Failed to add host %s to DHCP/DNS" % (instance.name))
 
 	def postDestroy(self, instance):
+		if (len(instance.nics) < 1):
+			return
 		try:
 			ip = socket.gethostbyname(instance.name)
 			ipNum = self.strToIp(ip)



Mime
View raw message