From a6de767f02153b46d964d551f10bc9561aa28d0c Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Thu, 23 Jul 2020 17:16:58 -0400 Subject: [PATCH] Make static OPNFV references dynamic Change-Id: I3830a30a927834b642052643d94c39a9faec4d54 Signed-off-by: Sean Smith --- src/account/migrations/0005_auto_20200723_2100.py | 23 +++++++++++++++++++++++ src/account/models.py | 5 ++++- src/notifier/manager.py | 5 +++-- src/resource_inventory/pdf_templater.py | 2 +- src/templates/base/notifier/email_ended.txt | 6 +++--- src/templates/base/notifier/email_expiring.txt | 6 +++--- src/templates/base/notifier/email_fulfilled.txt | 4 ++-- src/templates/base/notifier/end_booking.html | 6 +++--- src/templates/base/notifier/expiring_booking.html | 2 +- src/templates/base/notifier/new_booking.html | 2 +- 10 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 src/account/migrations/0005_auto_20200723_2100.py diff --git a/src/account/migrations/0005_auto_20200723_2100.py b/src/account/migrations/0005_auto_20200723_2100.py new file mode 100644 index 0000000..d995f80 --- /dev/null +++ b/src/account/migrations/0005_auto_20200723_2100.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2 on 2020-07-23 21:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0004_downtime'), + ] + + operations = [ + migrations.AddField( + model_name='lab', + name='lab_info_link', + field=models.URLField(null=True), + ), + migrations.AddField( + model_name='lab', + name='project', + field=models.CharField(default='LaaS', max_length=100), + ), + ] diff --git a/src/account/models.py b/src/account/models.py index 4aab306..03b31df 100644 --- a/src/account/models.py +++ b/src/account/models.py @@ -16,6 +16,7 @@ import random from collections import Counter + class LabStatus(object): """ A Poor man's enum for the status of a lab. @@ -204,6 +205,8 @@ class Lab(models.Model): # This token must apear in API requests from this lab api_token = models.CharField(max_length=50) description = models.CharField(max_length=240) + lab_info_link = models.URLField(null=True) + project = models.CharField(default='LaaS', max_length=100) @staticmethod def make_api_token(): @@ -216,7 +219,7 @@ class Lab(models.Model): def get_available_resources(self): # Cannot import model normally due to ciruclar import - Server = apps.get_model('resource_inventory', 'Server') # TODO: Find way to import ResourceQuery + Server = apps.get_model('resource_inventory', 'Server') # TODO: Find way to import ResourceQuery resources = [str(resource.profile) for resource in Server.objects.filter(lab=self, booked=False)] return dict(Counter(resources)) diff --git a/src/notifier/manager.py b/src/notifier/manager.py index 6d75a79..8ea8021 100644 --- a/src/notifier/manager.py +++ b/src/notifier/manager.py @@ -1,5 +1,6 @@ ############################################################################## # Copyright (c) 2018 Parker Berberian, Sawyer Bergeron and others. +# Copyright (c) 2020 Sawyer Bergeron, Sean Smith, and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -110,7 +111,7 @@ class NotificationHandler(object): @classmethod def email_booking_over(cls, booking): template_name = "notifier/email_ended.txt" - hostnames = [host.name for host in booking.resource.getResources()] + hostnames = [host.name for host in booking.resource.get_resources()] users = list(booking.collaborators.all()) users.append(booking.owner) for user in users: @@ -134,7 +135,7 @@ class NotificationHandler(object): @classmethod def email_booking_expiring(cls, booking): template_name = "notifier/email_expiring.txt" - hostnames = [host.name for host in booking.resource.getResources()] + hostnames = [host.name for host in booking.resource.get_resources()] users = list(booking.collaborators.all()) users.append(booking.owner) for user in users: diff --git a/src/resource_inventory/pdf_templater.py b/src/resource_inventory/pdf_templater.py index 27a264e..86d84aa 100644 --- a/src/resource_inventory/pdf_templater.py +++ b/src/resource_inventory/pdf_templater.py @@ -37,7 +37,7 @@ class PDFTemplater: lab = resource_lab.name location = resource_lab.location pod_type = "development" - link = "https://wiki.opnfv.org/display/INF/Laas" + link = resource_lab.lab_info_link try: # try to get more specific info that may fail, we dont care if it does diff --git a/src/templates/base/notifier/email_ended.txt b/src/templates/base/notifier/email_ended.txt index 1788e00..33a1ec5 100644 --- a/src/templates/base/notifier/email_ended.txt +++ b/src/templates/base/notifier/email_ended.txt @@ -1,9 +1,9 @@ {{user_name|default:"Developer"}}, {% if owner %} -The booking you requested from the OPNFV Lab as a Service has ended. +The booking you requested from the {{booking.lab.project}} Lab has ended. {% else %} -The booking you collaborated on at the OPNFV Lab as a Service has ended. +The booking you collaborated on at the {{booking.lab.project}} Lab has ended. {% endif %} booking information: @@ -20,6 +20,6 @@ You may visit the following link for more information: Feel free to create another booking with us! -Thank you for contributing to the OPNFV platform! +Thank you for contributing to the {{booking.lab.project}} platform! - The Lab-as-a-Service team diff --git a/src/templates/base/notifier/email_expiring.txt b/src/templates/base/notifier/email_expiring.txt index 72c9a83..d78e59f 100644 --- a/src/templates/base/notifier/email_expiring.txt +++ b/src/templates/base/notifier/email_expiring.txt @@ -1,9 +1,9 @@ {{user_name|default:"Developer"}}, {% if owner %} -The booking you requested from the OPNFV Lab as a Service is about to expire. +The booking you requested from the {{booking.lab.project}} lab is about to expire. {% else %} -The booking you collaborate on at the OPNFV Lab as a Service is about to expire. +The booking you collaborate on at the {{booking.lab.project}} lab is about to expire. {% endif %} booking information: @@ -20,6 +20,6 @@ You may visit the following link for more information: Please take the time to backup all data or extend the booking if needed. -Thank you for contributing to the OPNFV platform! +Thank you for contributing to the {{booking.lab.project}} platform! - The Lab-as-a-Service team diff --git a/src/templates/base/notifier/email_fulfilled.txt b/src/templates/base/notifier/email_fulfilled.txt index 90d294a..e3e07f9 100644 --- a/src/templates/base/notifier/email_fulfilled.txt +++ b/src/templates/base/notifier/email_fulfilled.txt @@ -1,7 +1,7 @@ {{user_name|default:"Developer"}}, {% if owner %} -The booking you requested of the OPNFV Lab as a Service has finished deploying and is ready for you to use. +The booking you requested of the {{booking.lab.project}} lab has finished deploying and is ready for you to use. {% else %} A booking you collaborate on is ready for you to use {% endif %} @@ -16,6 +16,6 @@ The lab that fulfilled your booking request has sent you the following messages: You may visit the following link for more information: {{booking_url}} -Thank you for contributing to the OPNFV platform! +Thank you for contributing to the {{booking.lab.project}} platform! - The Lab-as-a-Service team diff --git a/src/templates/base/notifier/end_booking.html b/src/templates/base/notifier/end_booking.html index a2981c1..ebad027 100644 --- a/src/templates/base/notifier/end_booking.html +++ b/src/templates/base/notifier/end_booking.html @@ -4,11 +4,11 @@ {% if owner %}

Your booking has expired

Your booking has ended and the machines have been cleaned up.

-

Thank you for working on OPNFV, and feel free to book more machines if you need them.

+

Thank you for working on {{booking.lab.project}}, and feel free to book more machines if you need them.

{% else %}

A booking that you collaborated on has expired

The booking owned by {{booking.owner.username}} that you worked on has ended

-

Thank you for contributing to OPNFV!

+

Thank you for contributing to {{booking.lab.project}}.

{% endif %}

Booking information: