in src/tashi/agents/dhcpdns.py [0:0]
def allocateIP(self, nic):
# XXXstroucki: if the network is not defined having an ip
# range, this will throw a KeyError. Should be logged.
network = nic.network
allocatedIP = None
requestedIP = self.strToIp(nic.ip)
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))
if (self.currentIP[network] > self.ipMax[network]):
self.currentIP[network] = self.ipMin[network]
wrapToMinAlready = True
elif (self.currentIP[network] in self.usedIPs):
self.currentIP[network] = self.currentIP[network] + 1
else:
allocatedIP = self.currentIP[network]
ipString = self.ipToStr(allocatedIP)
self.usedIPs[allocatedIP] = ipString
return ipString