From tashi-commits-return-71-apmail-incubator-tashi-commits-archive=incubator.apache.org@incubator.apache.org Wed Apr 29 18:30:08 2009 Return-Path: Delivered-To: apmail-incubator-tashi-commits-archive@minotaur.apache.org Received: (qmail 62963 invoked from network); 29 Apr 2009 18:30:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Apr 2009 18:30:08 -0000 Received: (qmail 95323 invoked by uid 500); 29 Apr 2009 18:30:08 -0000 Delivered-To: apmail-incubator-tashi-commits-archive@incubator.apache.org Received: (qmail 95301 invoked by uid 500); 29 Apr 2009 18:30:08 -0000 Mailing-List: contact tashi-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: tashi-dev@incubator.apache.org Delivered-To: mailing list tashi-commits@incubator.apache.org Received: (qmail 95291 invoked by uid 99); 29 Apr 2009 18:30:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Apr 2009 18:30:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Apr 2009 18:30:02 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1CD4523889D7; Wed, 29 Apr 2009 18:29:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r769864 - in /incubator/tashi/trunk: etc/TashiDefaults.cfg src/tashi/agents/dhcpdns.py Date: Wed, 29 Apr 2009 18:29:42 -0000 To: tashi-commits@incubator.apache.org From: mryan3@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090429182942.1CD4523889D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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)