Commit e9a14e71 by Bach Dániel Committed by Guba Sándor

vm: fix Interface.generate_mac()

parent d8441130
...@@ -35,6 +35,12 @@ class MACAddressField(models.Field): ...@@ -35,6 +35,12 @@ class MACAddressField(models.Field):
def get_internal_type(self): def get_internal_type(self):
return 'CharField' return 'CharField'
def to_python(self, value):
if not mac_re.search(str(value)):
raise ValidationError(
MACAddressFormField.default_error_messages['invalid'])
return str(value)
def formfield(self, **kwargs): def formfield(self, **kwargs):
defaults = {'form_class': MACAddressFormField} defaults = {'form_class': MACAddressFormField}
defaults.update(kwargs) defaults.update(kwargs)
......
...@@ -67,10 +67,12 @@ class Interface(Model): ...@@ -67,10 +67,12 @@ class Interface(Model):
# MAC 02:XX:XX:XX:XX:XX # MAC 02:XX:XX:XX:XX:XX
# \________/\__/ # \________/\__/
# VM ID VLAN ID # VM ID VLAN ID
class mac_custom(mac_unix):
word_fmt = '%.2X'
i = instance.id & 0xfffffff i = instance.id & 0xfffffff
v = vlan.vid & 0xfff v = vlan.vid & 0xfff
m = (0x02 << 40) | (i << 12) | v m = (0x02 << 40) | (i << 12) | v
return EUI(m, dialect=mac_unix) return EUI(m, dialect=mac_custom)
def get_vmnetwork_desc(self): def get_vmnetwork_desc(self):
return { return {
...@@ -108,6 +110,7 @@ class Interface(Model): ...@@ -108,6 +110,7 @@ class Interface(Model):
host.ipv4 = addresses['ipv4'] host.ipv4 = addresses['ipv4']
host.ipv6 = addresses['ipv6'] host.ipv6 = addresses['ipv6']
host.owner = owner host.owner = owner
host.full_clean()
host.save() host.save()
else: else:
host = None host = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment