def validate(self, value): """ ensure valid mac """ super(MacAddressField, self).validate(value) try: eui.EUI(value) except eui.AddrFormatError: raise ValidationError(_('Invalid mac address'))
r"^([A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9]|[A-Za-z0-9])$") ############## # Interfaces # ############## # The default format for displaying MAC addresses. This defaults to # ":"-separated and expanded (e.g. '00:00:00:00:00:00') MACADDRESS_DEFAULT_DIALECT = 'macaddress.mac_linux' # The default speed in Mbps for newly device interfaces if not otherwise # specified. INTERFACE_DEFAULT_SPEED = 1000 # In Mbps (e.g. 1Gbps) # Default MAC address ('00:00:00:00:00:00') INTERFACE_DEFAULT_MAC = eui.EUI(0, dialect=macaddress.default_dialect()) # These are mappings to the formal integer types from SNMP IF-MIB::ifType. The # types listed here are the most commonly found in the wild. # # *IF YOU ARE GOING TO MODIFY THIS*: This MUST be a list of 2-tuples of # (iftype, name), where iftype is the unique ID for the IANA ifType SNMP MIB, # and name is whatever name your little heart desires, but hopefully matches # the legit description according to the MIB. # # Ref: https://www.iana.org/assignments/ianaiftype-mib/ianaiftype-mib INTERFACE_TYPE_CHOICES = ( (6, 'ethernet'), # for all ethernet-like interfaces (1, 'other'), # none of the following (135, 'l2vlan'), # Layer 2 Virtual LAN using 802.1Q (136, 'l3vlan'), # Layer 3 Virtual LAN using IP
def to_internal_value(self, value): try: return eui.EUI(value) except eui.AddrFormatError: raise ValidationError(_('Invalid mac address'))