diff options
author | Parker Berberian <pberberian@iol.unh.edu> | 2019-08-12 14:18:25 -0400 |
---|---|---|
committer | Parker Berberian <pberberian@iol.unh.edu> | 2019-08-13 12:49:44 -0400 |
commit | d78fcef6ec55dbaa225c6607bdac430539bf3f0b (patch) | |
tree | 653cc5a73b3f2508c8ec93bf3055a3d87497929d /src/account | |
parent | 3418c7a7baae772f1bb58e9a827c1e6198dbed54 (diff) |
Adds Downtime Awareness
This adds a Downtime model and relevant operations so that
the dashboard knows when a lab is down for maintenance and
can act accordingly.
This change doesn't modify the front end at all,
but it does pass relevant downtime info to the
templates so that they can be updated in a future change.
Change-Id: Idb88b15838b949f352f11a31a1fce9749d283d28
Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'src/account')
-rw-r--r-- | src/account/migrations/0004_downtime.py | 24 | ||||
-rw-r--r-- | src/account/models.py | 20 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/account/migrations/0004_downtime.py b/src/account/migrations/0004_downtime.py new file mode 100644 index 0000000..fc700d1 --- /dev/null +++ b/src/account/migrations/0004_downtime.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2 on 2019-08-13 16:45 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0003_publicnetwork'), + ] + + operations = [ + migrations.CreateModel( + name='Downtime', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('start', models.DateTimeField()), + ('end', models.DateTimeField()), + ('description', models.TextField(default='This lab will be down for maintenance')), + ('lab', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.Lab')), + ], + ), + ] 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) |