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_next_aton_try(self, aton_try): # DEBUG print "NEED NEXT: %s try: %s" % (self, netutils.inet_ntoa(aton_try)) if self.topology == 'net30': a_try = netutils.inet_ntoa(aton_try) octets = a_try.split(".") rv = self.__get_net30_next_aton_try_by_octets(octets) # DEBUG print "FOUND: %s try: %s" % (self, netutils.inet_ntoa(rv)) else: # i.e. if self.topology == 'subnet': rv = super(VPNSubnet, self).get_next_aton_try(aton_try) return rv
def get_next_aton_try(self, aton_try): # DEBUG print "NEED NEXT: %s try: %s" % (self, netutils.inet_ntoa(aton_try)) if self.topology == 'net30': a_try = netutils.inet_ntoa(aton_try) octets = a_try.split(".") rv = self.__get_net30_next_aton_try_by_octets(octets) # DEBUG print "FOUND: %s try: %s" % (self, netutils.inet_ntoa(rv)) else: # i.e. if self.topology == 'subnet': rv = super(VPNSubnet, self).get_next_aton_try(aton_try) return rv
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 dotted_quad_netmask(self): num = 0 for i in range(31, 31 - self.bits, -1): num += 2**i return netutils.inet_ntoa(num)
def dotted_quad_netmask(self): num = 0 for i in range(31, 31 - self.bits, -1): num += 2**i return netutils.inet_ntoa(num)