Parcourir la source

Fixes #1717: Fixed inteface validation for virtual machines

Jeremy Stretch il y a 7 ans
Parent
commit
0cb3e1749b
1 fichiers modifiés avec 10 ajouts et 5 suppressions
  1. 10 5
      netbox/dcim/models.py

+ 10 - 5
netbox/dcim/models.py

@@ -1120,6 +1120,8 @@ class ConsoleServerPort(models.Model):
     def clean(self):
     def clean(self):
 
 
         # Check that the parent device's DeviceType is a console server
         # Check that the parent device's DeviceType is a console server
+        if self.device is None:
+            raise ValidationError("Console server ports must be assigned to devices.")
         device_type = self.device.device_type
         device_type = self.device.device_type
         if not device_type.is_console_server:
         if not device_type.is_console_server:
             raise ValidationError("The {} {} device type not support assignment of console server ports.".format(
             raise ValidationError("The {} {} device type not support assignment of console server ports.".format(
@@ -1194,6 +1196,8 @@ class PowerOutlet(models.Model):
     def clean(self):
     def clean(self):
 
 
         # Check that the parent device's DeviceType is a PDU
         # Check that the parent device's DeviceType is a PDU
+        if self.device is None:
+            raise ValidationError("Power outlets must be assigned to devices.")
         device_type = self.device.device_type
         device_type = self.device.device_type
         if not device_type.is_pdu:
         if not device_type.is_pdu:
             raise ValidationError("The {} {} device type not support assignment of power outlets.".format(
             raise ValidationError("The {} {} device type not support assignment of power outlets.".format(
@@ -1257,11 +1261,12 @@ class Interface(models.Model):
     def clean(self):
     def clean(self):
 
 
         # Check that the parent device's DeviceType is a network device
         # 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
-            ))
+        if self.device is not None:
+            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: