mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Add WirelessLink model
This commit is contained in:
@@ -6,19 +6,22 @@ from dcim.constants import WIRELESS_IFACE_TYPES
|
||||
from extras.utils import extras_features
|
||||
from netbox.models import BigIDModel, PrimaryModel
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
from .constants import SSID_MAX_LENGTH
|
||||
|
||||
__all__ = (
|
||||
'WirelessLAN',
|
||||
'WirelessLink',
|
||||
)
|
||||
|
||||
|
||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||
class WirelessLAN(PrimaryModel):
|
||||
"""
|
||||
A service set identifier belonging to a wireless network.
|
||||
A wireless network formed among an arbitrary number of access point and clients.
|
||||
"""
|
||||
ssid = models.CharField(
|
||||
max_length=32
|
||||
max_length=SSID_MAX_LENGTH,
|
||||
verbose_name='SSID'
|
||||
)
|
||||
vlan = models.ForeignKey(
|
||||
to='ipam.VLAN',
|
||||
@@ -42,4 +45,78 @@ class WirelessLAN(PrimaryModel):
|
||||
return self.ssid
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('wireless:ssid', args=[self.pk])
|
||||
return reverse('wireless:wirelesslan', args=[self.pk])
|
||||
|
||||
|
||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||
class WirelessLink(PrimaryModel):
|
||||
"""
|
||||
A point-to-point connection between two wireless Interfaces.
|
||||
"""
|
||||
interface_a = models.ForeignKey(
|
||||
to='dcim.Interface',
|
||||
limit_choices_to={'type__in': WIRELESS_IFACE_TYPES},
|
||||
on_delete=models.PROTECT,
|
||||
related_name='+'
|
||||
)
|
||||
interface_b = models.ForeignKey(
|
||||
to='dcim.Interface',
|
||||
limit_choices_to={'type__in': WIRELESS_IFACE_TYPES},
|
||||
on_delete=models.PROTECT,
|
||||
related_name='+'
|
||||
)
|
||||
ssid = models.CharField(
|
||||
max_length=SSID_MAX_LENGTH,
|
||||
blank=True,
|
||||
verbose_name='SSID'
|
||||
)
|
||||
description = models.CharField(
|
||||
max_length=200,
|
||||
blank=True
|
||||
)
|
||||
|
||||
# Cache the associated device for the A and B interfaces. This enables filtering of WirelessLinks by their
|
||||
# associated Devices.
|
||||
_interface_a_device = models.ForeignKey(
|
||||
to='dcim.Device',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='+',
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
_interface_b_device = models.ForeignKey(
|
||||
to='dcim.Device',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='+',
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
||||
objects = RestrictedQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
ordering = ['pk']
|
||||
unique_together = ('interface_a', 'interface_b')
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('wireless:wirelesslink', args=[self.pk])
|
||||
|
||||
def clean(self):
|
||||
|
||||
# Validate interface types
|
||||
if self.interface_a.type not in WIRELESS_IFACE_TYPES:
|
||||
raise ValidationError({
|
||||
'interface_a': f"{self.interface_a.get_type_display()} is not a wireless interface."
|
||||
})
|
||||
if self.interface_b.type not in WIRELESS_IFACE_TYPES:
|
||||
raise ValidationError({
|
||||
'interface_a': f"{self.interface_b.get_type_display()} is not a wireless interface."
|
||||
})
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
# Store the parent Device for the A and B interfaces
|
||||
self._interface_a_device = self.interface_a.device
|
||||
self._interface_b_device = self.interface_b.device
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user