示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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
示例#4
0
    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
示例#5
0
    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))
示例#6
0
    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))
示例#7
0
 def dotted_quad_netmask(self):
     num = 0
     for i in range(31, 31 - self.bits, -1):
         num += 2**i
     return netutils.inet_ntoa(num)
示例#8
0
 def dotted_quad_netmask(self):
     num = 0
     for i in range(31, 31 - self.bits, -1):
         num += 2**i
     return netutils.inet_ntoa(num)