diff options
author | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2019-08-29 16:35:53 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2019-08-29 16:35:53 +0000 |
commit | 01bdb95d22840393a20378559cf3cf59c4bdce78 (patch) | |
tree | 7880970eb7f55c2e9a6af7ada2ee5900cac9e2be /src/account/models.py | |
parent | 99f96e86bdf78e9d93ad1d259fc18e3fff772720 (diff) | |
parent | d78fcef6ec55dbaa225c6607bdac430539bf3f0b (diff) |
Merge "Adds Downtime Awareness"
Diffstat (limited to 'src/account/models.py')
-rw-r--r-- | src/account/models.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/account/models.py b/src/account/models.py index 4fc7c40..4862231 100644 --- a/src/account/models.py +++ b/src/account/models.py @@ -168,3 +168,23 @@ class PublicNetwork(models.Model): in_use = models.BooleanField(default=False) cidr = models.CharField(max_length=50, default="0.0.0.0/0") gateway = models.CharField(max_length=50, default="0.0.0.0") + + +class Downtime(models.Model): + start = models.DateTimeField() + end = models.DateTimeField() + lab = models.ForeignKey(Lab, on_delete=models.CASCADE) + description = models.TextField(default="This lab will be down for maintenance") + + def save(self, *args, **kwargs): + if self.start >= self.end: + raise ValueError('Start date is after end date') + + # check for overlapping downtimes + overlap_start = Downtime.objects.filter(lab=self.lab, start__gt=self.start, start__lt=self.end).exists() + overlap_end = Downtime.objects.filter(lab=self.lab, end__lt=self.end, end__gt=self.start).exists() + + if overlap_start or overlap_end: + raise ValueError('Overlapping Downtime') + + return super(Downtime, self).save(*args, **kwargs) |