mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 03:56:53 -06:00
Fixes #1642: Validate device type classification when creating console server ports and power outlets
This commit is contained in:
parent
a0bb7b08bd
commit
30b544a743
@ -1117,6 +1117,15 @@ class ConsoleServerPort(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
|
||||||
|
# Check that the parent device's DeviceType is a console server
|
||||||
|
device_type = self.device.device_type
|
||||||
|
if not device_type.is_console_server:
|
||||||
|
raise ValidationError("The {} {} device type not support assignment of console server ports.".format(
|
||||||
|
device_type.manufacturer, device_type
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Power ports
|
# Power ports
|
||||||
@ -1182,6 +1191,15 @@ class PowerOutlet(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
|
||||||
|
# Check that the parent device's DeviceType is a PDU
|
||||||
|
device_type = self.device.device_type
|
||||||
|
if not device_type.is_pdu:
|
||||||
|
raise ValidationError("The {} {} device type not support assignment of power outlets.".format(
|
||||||
|
device_type.manufacturer, device_type
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Interfaces
|
# Interfaces
|
||||||
@ -1238,6 +1256,13 @@ class Interface(models.Model):
|
|||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
|
# Check that the parent device's DeviceType is a network device
|
||||||
|
device_type = self.device.device_type
|
||||||
|
if not device_type.is_network_device:
|
||||||
|
raise ValidationError("The {} {} device type not support assignment of network interfaces.".format(
|
||||||
|
device_type.manufacturer, device_type
|
||||||
|
))
|
||||||
|
|
||||||
# An Interface must belong to a Device *or* to a VirtualMachine
|
# An Interface must belong to a Device *or* to a VirtualMachine
|
||||||
if self.device and self.virtual_machine:
|
if self.device and self.virtual_machine:
|
||||||
raise ValidationError("An interface cannot belong to both a device and a virtual machine.")
|
raise ValidationError("An interface cannot belong to both a device and a virtual machine.")
|
||||||
|
@ -1432,7 +1432,7 @@ class ConsoleServerPortTest(HttpStatusMixin, APITestCase):
|
|||||||
site = Site.objects.create(name='Test Site 1', slug='test-site-1')
|
site = Site.objects.create(name='Test Site 1', slug='test-site-1')
|
||||||
manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
|
manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
|
||||||
devicetype = DeviceType.objects.create(
|
devicetype = DeviceType.objects.create(
|
||||||
manufacturer=manufacturer, model='Test Device Type 1', slug='test-device-type-1'
|
manufacturer=manufacturer, model='Test Device Type 1', slug='test-device-type-1', is_console_server=True
|
||||||
)
|
)
|
||||||
devicerole = DeviceRole.objects.create(
|
devicerole = DeviceRole.objects.create(
|
||||||
name='Test Device Role 1', slug='test-device-role-1', color='ff0000'
|
name='Test Device Role 1', slug='test-device-role-1', color='ff0000'
|
||||||
@ -1590,7 +1590,7 @@ class PowerOutletTest(HttpStatusMixin, APITestCase):
|
|||||||
site = Site.objects.create(name='Test Site 1', slug='test-site-1')
|
site = Site.objects.create(name='Test Site 1', slug='test-site-1')
|
||||||
manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
|
manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
|
||||||
devicetype = DeviceType.objects.create(
|
devicetype = DeviceType.objects.create(
|
||||||
manufacturer=manufacturer, model='Test Device Type 1', slug='test-device-type-1'
|
manufacturer=manufacturer, model='Test Device Type 1', slug='test-device-type-1', is_pdu=True
|
||||||
)
|
)
|
||||||
devicerole = DeviceRole.objects.create(
|
devicerole = DeviceRole.objects.create(
|
||||||
name='Test Device Role 1', slug='test-device-role-1', color='ff0000'
|
name='Test Device Role 1', slug='test-device-role-1', color='ff0000'
|
||||||
@ -1667,7 +1667,7 @@ class InterfaceTest(HttpStatusMixin, APITestCase):
|
|||||||
site = Site.objects.create(name='Test Site 1', slug='test-site-1')
|
site = Site.objects.create(name='Test Site 1', slug='test-site-1')
|
||||||
manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
|
manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
|
||||||
devicetype = DeviceType.objects.create(
|
devicetype = DeviceType.objects.create(
|
||||||
manufacturer=manufacturer, model='Test Device Type 1', slug='test-device-type-1'
|
manufacturer=manufacturer, model='Test Device Type 1', slug='test-device-type-1', is_network_device=True
|
||||||
)
|
)
|
||||||
devicerole = DeviceRole.objects.create(
|
devicerole = DeviceRole.objects.create(
|
||||||
name='Test Device Role 1', slug='test-device-role-1', color='ff0000'
|
name='Test Device Role 1', slug='test-device-role-1', color='ff0000'
|
||||||
|
Loading…
Reference in New Issue
Block a user