Esempio n. 1
0
    def clean_macaddress(self):
        """ Validate macaddress """
        macaddress = self.cleaned_data.get('macaddress', '')

        filteredmacaddress = strip_delimiters(macaddress)
        if len(filteredmacaddress) < MAC_ADDR_MIN_LEN:
            raise forms.ValidationError("Mac address/prefix is too short")
        if len(filteredmacaddress) > MAC_ADDR_MAX_LEN:
            raise forms.ValidationError("Mac address is too long")

        # Number hex-digits (or so-called nybbles),- since prefix may
        # get specified in hex-digits.
        # Set when a mac-address prefix is given.
        addr_len = len(filteredmacaddress)
        if (addr_len >= MAC_ADDR_MIN_LEN and addr_len < MAC_ADDR_MAX_LEN):
            self.prefix_length = addr_len

        filteredmacaddress = add_zeros_to_mac_addr(filteredmacaddress)

        if not has_legal_values(filteredmacaddress):
            raise forms.ValidationError(
                "Illegal values or format for mac address.")

        if int(MacWatch.objects.filter(mac=filteredmacaddress).count()) > 0:
            raise forms.ValidationError("This mac address is already watched.")

        return filteredmacaddress
Esempio n. 2
0
    def clean_macaddress(self):
        """ Validate macaddress """
        macaddress = self.cleaned_data.get('macaddress', '')

        filteredmacaddress = strip_delimiters(macaddress)
        if len(filteredmacaddress) < MAC_ADDR_MIN_LEN:
            raise forms.ValidationError("Mac address/prefix is too short")
        if len(filteredmacaddress) > MAC_ADDR_MAX_LEN:
            raise forms.ValidationError("Mac address is too long")

        # Number hex-digits (or so-called nybbles),- since prefix may
        # get specified in hex-digits.
        # Set when a mac-address prefix is given.
        addr_len = len(filteredmacaddress)
        if (addr_len >= MAC_ADDR_MIN_LEN and addr_len < MAC_ADDR_MAX_LEN):
            self.prefix_length = addr_len

        filteredmacaddress = add_zeros_to_mac_addr(filteredmacaddress)

        if not has_legal_values(filteredmacaddress):
            raise forms.ValidationError(
                "Illegal values or format for mac address.")

        if int(MacWatch.objects.filter(mac=filteredmacaddress).count()) > 0:
            raise forms.ValidationError("This mac address is already watched.")

        return filteredmacaddress