Commit 3d3bfaae by Bach Dániel Committed by Bach Dániel

firewall: new models: SwitchPort, EthernetDevice

parent e23b3021
......@@ -91,9 +91,11 @@ class IPNetworkField(models.Field):
if isinstance(value, IPNetwork):
if self.version == 4:
return '.'.join(map(lambda x: "%03d" % x, value.ip.words)) + '/%d' % value.prefixlen
return ('.'.join(["%03d" % x for x in value.ip.words])
+ '/%02d' % value.prefixlen)
else:
return ':'.join(map(lambda x: "%04X" % x, value.ip.words)) + '/%d' % value.prefixlen
return (':'.join(["%04X" % x for x in value.ip.words])
+ '/%03d' % value.prefixlen)
return value
def value_to_string(self, obj):
......
......@@ -440,7 +440,25 @@ def dhcp():
def vlan():
obj = models.Vlan.objects.values('vid', 'name', 'network4', 'network6')
return {x['name']: {'tag': x['vid'],
'addresses': [str(x['network4']),
str(x['network6'])]}
for x in obj}
retval = {x['name']: {'tag': x['vid'],
'type': 'internal',
'interfaces': [x['name']],
'addresses': [str(x['network4']),
str(x['network6'])]}
for x in obj}
for p in models.SwitchPort.objects.all():
eth_count = p.ethernet_devices.count()
if eth_count > 1:
name = 'bond%d' % p.id
elif eth_count == 1:
name = p.ethernet_devices.get().name
else: # 0
continue
tag = p.untagged_vlan.vid
retval[name] = {'tag': tag}
if p.tagged_vlans is not None:
trunk = list(p.tagged_vlans.vlans.values_list('vid', flat=True))
retval[name]['trunks'] = sorted(trunk)
retval[name]['interfaces'] = list(
p.ethernet_devices.values_list('name', flat=True))
return retval
......@@ -768,6 +768,47 @@ class Record(models.Model):
)
class SwitchPort(models.Model):
untagged_vlan = models.ForeignKey('Vlan',
related_name='untagged_ports',
verbose_name=_('untagged vlan'))
tagged_vlans = models.ForeignKey('VlanGroup', blank=True, null=True,
related_name='tagged_ports',
verbose_name=_('tagged vlans'))
description = models.TextField(blank=True, verbose_name=_('description'))
created_at = models.DateTimeField(auto_now_add=True,
verbose_name=_('created_at'))
modified_at = models.DateTimeField(auto_now=True,
verbose_name=_('modified_at'))
def __unicode__(self):
devices = ','.join(self.ethernet_devices.values_list('name',
flat=True))
tagged_vlans = self.tagged_vlans.name if self.tagged_vlans else ''
return 'devices=%s untagged=%s tagged=%s' % (devices,
self.untagged_vlan,
tagged_vlans)
class EthernetDevice(models.Model):
name = models.CharField(max_length=20,
unique=True,
verbose_name=_('interface'),
help_text=_('The name of network interface the '
'gateway should serve this network '
'on. For example eth2.'))
switch_port = models.ForeignKey('SwitchPort',
related_name='ethernet_devices',
verbose_name=_('switch port'))
created_at = models.DateTimeField(auto_now_add=True,
verbose_name=_('created_at'))
modified_at = models.DateTimeField(auto_now=True,
verbose_name=_('modified_at'))
def __unicode__(self):
return self.name
class Blacklist(models.Model):
CHOICES_type = (('permban', 'permanent ban'), ('tempban', 'temporary ban'),
('whitelist', 'whitelist'), ('tempwhite', 'tempwhite'))
......
......@@ -56,7 +56,7 @@ def reloadtask(type='Host'):
if type == "Blacklist":
cache.add("blacklist_lock", "true", 30)
if type == "Vlan":
if type in ["Vlan", "SwitchPort", "EthernetDevice"]:
cache.add("firewall_vlan_lock", "true", 30)
print type
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