def get_free_ip4(self): aton_min = netutils.inet_aton(self.static_min) aton_max = netutils.inet_aton(self.static_max) aton_try = self.get_start_aton_try() bound_client_list = self.client_set.all().order_by('ip') # print "AAAA %s %s - %s" % (self, self.static_min, self.static_max) # print bound_client_list if len(bound_client_list): ordered_ip4_aton_list = map(lambda obj: netutils.inet_aton(obj.ip), bound_client_list) ordered_ip4_aton_list.sort() for aton_ip4 in ordered_ip4_aton_list: if aton_ip4 >= aton_min: if (aton_try == aton_max): raise Subnet.SubnetFullException elif (aton_try == aton_ip4): # Try next one aton_try = self.get_next_aton_try(aton_try) else: # Found! rv = aton_try break else: rv = aton_try return netutils.inet_ntoa(aton_try)
def get_free_ip4(self): aton_min = netutils.inet_aton(self.static_min) aton_max = netutils.inet_aton(self.static_max) aton_try = self.get_start_aton_try() bound_client_list = self.client_set.all().order_by('ip') # print "AAAA %s %s - %s" % (self, self.static_min, self.static_max) # print bound_client_list if len(bound_client_list): ordered_ip4_aton_list = map(lambda obj: netutils.inet_aton(obj.ip), bound_client_list) ordered_ip4_aton_list.sort() for aton_ip4 in ordered_ip4_aton_list: if aton_ip4 >= aton_min: if (aton_try == aton_max): raise Subnet.SubnetFullException elif (aton_try == aton_ip4): # Try next one aton_try = self.get_next_aton_try(aton_try) else: # Found! rv = aton_try break else: rv = aton_try return netutils.inet_ntoa(aton_try)
def __get_net30_next_aton_try_by_octets(self, octets): i = 0 TOPO_VLO = self.TOPOLOGY_NET30_VALID_LAST_OCTETS try: while TOPO_VLO[i][0] <= int(octets[-1]): # DEBUG print "%s %s - %s" % ("a", self.topology, octets) i += 1 octets[-1] = str(TOPO_VLO[i][0]) a_try = ".".join(octets) aton_try = netutils.inet_aton(a_try) except IndexError: # Corner case. i.e. static_min is > x.y.z.253 # Set it to the end. Convert to integer and increment by 2 to get (x.y.z.)+1.1 octets[-1] = '255' a_try = ".".join(octets) aton_try = netutils.inet_aton(a_try) + 2 return aton_try
def __get_net30_next_aton_try_by_octets(self, octets): i = 0 TOPO_VLO = self.TOPOLOGY_NET30_VALID_LAST_OCTETS try: while TOPO_VLO[i][0] <= int(octets[-1]): # DEBUG print "%s %s - %s" % ("a", self.topology, octets) i += 1 octets[-1] = str(TOPO_VLO[i][0]) a_try = ".".join(octets) aton_try = netutils.inet_aton(a_try) except IndexError: # Corner case. i.e. static_min is > x.y.z.253 # Set it to the end. Convert to integer and increment by 2 to get (x.y.z.)+1.1 octets[-1] = '255' a_try = ".".join(octets) aton_try = netutils.inet_aton(a_try) + 2 return aton_try
def fix_client_ip(self): log.info("Fixing client %s ip address %s" % (self, self.ip)) # Move ip to the end of the list subnet = self.subnet bound_client_list = subnet.client_set.all().order_by('ip') ordered_ip4_aton_list = map(lambda obj: netutils.inet_aton(obj.ip), bound_client_list) ordered_ip4_aton_list.sort() aton_new_ip4 = subnet.get_next_aton_try(ordered_ip4_aton_list[-1]) self.ip = netutils.inet_ntoa(aton_new_ip4) self.enabled = False self.save() log.info("Updated client %s with ip address %s" % (self, self.ip))
def fix_client_ip(self): log.info("Fixing client %s ip address %s" % (self, self.ip)) # Move ip to the end of the list subnet = self.subnet bound_client_list = subnet.client_set.all().order_by('ip') ordered_ip4_aton_list = map(lambda obj: netutils.inet_aton(obj.ip), bound_client_list) ordered_ip4_aton_list.sort() aton_new_ip4 = subnet.get_next_aton_try(ordered_ip4_aton_list[-1]) self.ip = netutils.inet_ntoa(aton_new_ip4) self.enabled = False self.save() log.info("Updated client %s with ip address %s" % (self, self.ip))
def get_start_aton_try(self): return netutils.inet_aton(self.static_min)
def get_start_aton_try(self): return netutils.inet_aton(self.static_min)