Ejemplo n.º 1
0
 def update_reverse_domain(self):
     # We are assuming that self.clean_ip has been called already
     rvname = nibbilize(self.ip_str) if self.ip_type == '6' else self.ip_str
     rvname = ip_to_domain_name(rvname, ip_type=self.ip_type)
     self.reverse_domain = name_to_domain(rvname)
     if (self.reverse_domain is None or self.reverse_domain.name in
             ('arpa', 'in-addr.arpa', 'ip6.arpa')):
         raise ValidationError(
             "No reverse Domain found for {0} ".format(self.ip_str)
         )
Ejemplo n.º 2
0
 def reassign(objs):
     for obj in objs:
         if ip_type == '6':
             nibz = nibbilize(obj.ip_str)
             revname = ip_to_domain_name(nibz, ip_type='6')
         else:
             revname = ip_to_domain_name(obj.ip_str, ip_type='4')
         correct_reverse_domain = name_to_domain(revname)
         if correct_reverse_domain != obj.reverse_domain:
             # TODO, is this needed? The save() function (actually the
             # clean_ip function) will assign the correct reverse domain.
             obj.reverse_domain = correct_reverse_domain
             obj.save()
Ejemplo n.º 3
0
def reassign_reverse_ptrs(reverse_domain_1, reverse_domain_2, ip_type):
    """There are some formalities that need to happen when a reverse
    domain is added and deleted. For example, when adding say we had the
    ip address 128.193.4.0 and it had the reverse_domain 128.193. If we
    add the reverse_domain 128.193.4, our 128.193.4.0 no longer belongs
    to the 128.193 domain. We need to re-asign the ip to it's correct
    reverse domain.

    :param reverse_domain_1: The domain which could possible have
        addresses added to it.

    :type reverse_domain_1: str

    :param reverse_domain_2: The domain that has ip's which might not
        belong to it anymore.

    :type reverse_domain_2: str
    """

    if reverse_domain_2 is None or ip_type is None:
        return
    ptrs = reverse_domain_2.ptr_set.iterator()
    #intrs = reverse_domain_2.staticinterface_set.iterator()
    #TODO do the intr case
    for ptr in ptrs:
        if ip_type == '6':
            nibz = nibbilize(ptr.ip_str)
            revname = ip_to_domain_name(nibz, ip_type='6')
        else:
            revname = ip_to_domain_name(ptr.ip_str, ip_type='4')
        correct_reverse_domain = name_to_domain(revname)
        if correct_reverse_domain != ptr.reverse_domain:
            # TODO, is this needed? The save() function (actually the
            # clean_ip function) will assign the correct reverse domain.
            ptr.reverse_domain = correct_reverse_domain
            ptr.save()
Ejemplo n.º 4
0
def reassign_reverse_ptrs(reverse_domain_1, reverse_domain_2, ip_type):
    """There are some formalities that need to happen when a reverse
    domain is added and deleted. For example, when adding say we had the
    ip address 128.193.4.0 and it had the reverse_domain 128.193. If we
    add the reverse_domain 128.193.4, our 128.193.4.0 no longer belongs
    to the 128.193 domain. We need to re-asign the ip to it's correct
    reverse domain.

    :param reverse_domain_1: The domain which could possible have
        addresses added to it.

    :type reverse_domain_1: str

    :param reverse_domain_2: The domain that has ip's which might not
        belong to it anymore.

    :type reverse_domain_2: str
    """

    if reverse_domain_2 is None or ip_type is None:
        return
    ptrs = reverse_domain_2.ptr_set.iterator()
    #intrs = reverse_domain_2.staticinterface_set.iterator()
    #TODO do the intr case
    for ptr in ptrs:
        if ip_type == '6':
            nibz = nibbilize(ptr.ip_str)
            revname = ip_to_domain_name(nibz, ip_type='6')
        else:
            revname = ip_to_domain_name(ptr.ip_str, ip_type='4')
        correct_reverse_domain = name_to_domain(revname)
        if correct_reverse_domain != ptr.reverse_domain:
            # TODO, is this needed? The save() function (actually the
            # clean_ip function) will assign the correct reverse domain.
            ptr.reverse_domain = correct_reverse_domain
            ptr.save()
Ejemplo n.º 5
0
                    self.reverse_domain.name in ('arpa', 'in-addr.arpa',
                                                 'ipv6.arpa')):
                    raise ValidationError("No reverse Domain found for {0} "
                                          .format(self.ip_str))
            self.ip_upper = 0
            self.ip_lower = int(ip)
        else:
            try:
                ip = ipaddr.IPv6Address(self.ip_str)
                self.ip_str = str(ip)
            except ipaddr.AddressValueError, e:
                raise ValidationError("Invalid ip {0} for IPv6s.".
                                      format(self.ip_str))

            if update_reverse_domain:
                nibz = nibbilize(self.ip_str)
                revname = ip_to_domain_name(nibz, ip_type='6')
                self.reverse_domain = name_to_domain(revname)
                if (self.reverse_domain is None or self.reverse_domain.name in
                        ('arpa', 'in-addr.arpa', 'ipv6.arpa')):
                    raise ValidationError("No reverse Domain found for {0} "
                                          .format(self.ip_str))
            self.ip_upper, self.ip_lower = ipv6_to_longs(int(ip))

    def __int__(self):
        if self.ip_type == '4':
            self.ip_lower
        if self.ip_type == '6':
            return (self.ip_upper * (2 ** 64)) + self.ip_lower

    def _validate_ip_str(self):