aboutsummaryrefslogtreecommitdiffstats
path: root/src/resource_inventory/models.py
diff options
context:
space:
mode:
authorssmith <ssmith@iol.unh.edu>2020-05-18 18:08:35 -0400
committerssmith <ssmith@iol.unh.edu>2020-05-20 17:13:57 -0400
commit9ebe025e1385a0a4fa8e24ad62cc1c0f8808fb9c (patch)
tree3556ad5f3d6a70ce1756240cf68831a4b3684087 /src/resource_inventory/models.py
parent530271c247a4ce538e3aa69fd3893481fada44ab (diff)
Reworks resource tests into model validation where possible.
Change-Id: Ieb77cc38a42345107c2cac62ba1499bd7974ad77 Signed-off-by: Sean Smith <ssmith@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory/models.py')
-rw-r--r--src/resource_inventory/models.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/resource_inventory/models.py b/src/resource_inventory/models.py
index d1b7a75..33d98a0 100644
--- a/src/resource_inventory/models.py
+++ b/src/resource_inventory/models.py
@@ -439,6 +439,9 @@ class InterfaceConfiguration(models.Model):
def __str__(self):
return "type " + str(self.profile) + " on host " + str(self.resource_config)
+ def save(self, *args, **kwargs):
+ super().save(*args, **kwargs)
+
"""
OPNFV / Software configuration models
@@ -504,12 +507,21 @@ class Interface(models.Model):
mac_address = models.CharField(max_length=17)
bus_address = models.CharField(max_length=50)
config = models.ManyToManyField(Vlan)
- acts_as = models.OneToOneField(InterfaceConfiguration, null=True, on_delete=models.SET_NULL)
+ acts_as = models.OneToOneField(InterfaceConfiguration, null=True, on_delete=models.CASCADE)
profile = models.ForeignKey(InterfaceProfile, on_delete=models.CASCADE)
def __str__(self):
return self.mac_address + " on host " + str(self.profile.host.name)
+ def clean(self, *args, **kwargs):
+ if self.acts_as.profile != self.profile:
+ raise ValidationError("Interface Configuration's Interface Profile does not match Interface Profile chosen for Interface.")
+ super().clean(*args, **kwargs)
+
+ def save(self, *args, **kwargs):
+ self.full_clean()
+ super().save(*args, **kwargs)
+
"""
Some Enums for dealing with global constants.