summaryrefslogtreecommitdiffstats
path: root/dashboard/src/dashboard
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2018-11-20 11:19:55 -0500
committerParker Berberian <pberberian@iol.unh.edu>2018-11-26 14:07:15 -0500
commitf2bbdbbf7e03be031723a9680aa9deaf80e4a99c (patch)
tree54086b0ae60b65da0905e3b51c922934247b5370 /dashboard/src/dashboard
parent674812a20f6804c287e1355ec8a1adf907798a94 (diff)
Fix all flake8 errors
The flake8 command in test.sh finds no longer finds any errors. This may form a basis of a jenkins verify job as a sort of 'weak compile-time checks' The flake8 command will not complain about line length, and will not complain about django's manage.py file Change-Id: Ic47cb4fc7ada55e64485661ab6881aef475018ff Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'dashboard/src/dashboard')
-rw-r--r--dashboard/src/dashboard/context_processors.py1
-rw-r--r--dashboard/src/dashboard/exceptions.py6
-rw-r--r--dashboard/src/dashboard/populate_db_iol.py228
-rw-r--r--dashboard/src/dashboard/tasks.py20
-rw-r--r--dashboard/src/dashboard/templatetags/__init__.py2
-rw-r--r--dashboard/src/dashboard/tests/__init__.py2
-rw-r--r--dashboard/src/dashboard/urls.py9
-rw-r--r--dashboard/src/dashboard/views.py39
8 files changed, 163 insertions, 144 deletions
diff --git a/dashboard/src/dashboard/context_processors.py b/dashboard/src/dashboard/context_processors.py
index 32c70b8..338f609 100644
--- a/dashboard/src/dashboard/context_processors.py
+++ b/dashboard/src/dashboard/context_processors.py
@@ -8,5 +8,6 @@
##############################################################################
from django.conf import settings
+
def debug(context):
return {'DEBUG': settings.DEBUG}
diff --git a/dashboard/src/dashboard/exceptions.py b/dashboard/src/dashboard/exceptions.py
index bc3fcac..9c16a06 100644
--- a/dashboard/src/dashboard/exceptions.py
+++ b/dashboard/src/dashboard/exceptions.py
@@ -14,18 +14,21 @@ class ResourceProvisioningException(Exception):
"""
pass
+
class ModelValidationException(Exception):
"""
Validation before saving model returned issues
"""
pass
+
class ResourceAvailabilityException(ResourceProvisioningException):
"""
Requested resources are not *currently* available
"""
pass
+
class ResourceExistenceException(ResourceAvailabilityException):
"""
Requested resources do not exist or do not match any known resources
@@ -36,11 +39,14 @@ class ResourceExistenceException(ResourceAvailabilityException):
class NonUniqueHostnameException(Exception):
pass
+
class InvalidHostnameException(Exception):
pass
+
class InvalidVlanConfigurationException(Exception):
pass
+
class NetworkExistsException(Exception):
pass
diff --git a/dashboard/src/dashboard/populate_db_iol.py b/dashboard/src/dashboard/populate_db_iol.py
index 8c8b271..4368520 100644
--- a/dashboard/src/dashboard/populate_db_iol.py
+++ b/dashboard/src/dashboard/populate_db_iol.py
@@ -7,18 +7,27 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-
-from django.test import TestCase
-from booking.models import Booking
-from resource_inventory.models import *
-from account.models import *
-from api.serializers.booking_serializer import *
-from datetime import timedelta
-from django.utils import timezone
-from django.contrib.auth.models import Permission, User
import json
import yaml
+from account.models import Lab, UserProfile
+from django.contrib.auth.models import User
+from resource_inventory.models import (
+ HostProfile,
+ InterfaceProfile,
+ DiskProfile,
+ CpuProfile,
+ RamProfile,
+ VlanManager,
+ Scenario,
+ Installer,
+ Opsys,
+ OPNFVRole,
+ Image,
+ Interface,
+ Host
+)
+
class Populator:
@@ -29,7 +38,6 @@ class Populator:
self.generic_bundle_count = 0
self.booking_count = 0
-
def make_host_profile(self, lab, data):
hostProfile = HostProfile.objects.create(
host_type=data['host']['type'],
@@ -47,7 +55,6 @@ class Populator:
)
interfaceProfile.save()
-
for disk_data in data['disks']:
diskProfile = DiskProfile.objects.create(
@@ -84,41 +91,38 @@ class Populator:
user_sbergeron.save()
user_sbergeron_prof = UserProfile.objects.create(user=user_sbergeron)
user_sbergeron_prof.save()
- return [user_sbergeron, user_pberberian,]
-
+ return [user_sbergeron, user_pberberian]
def make_labs(self):
unh_iol = User.objects.create(username="unh_iol")
unh_iol.save()
vlans = []
reserved = []
- for i in range(1,4096):
+ for i in range(1, 4096):
vlans.append(1)
reserved.append(0)
- # TODO: put reserved vlans here
iol = Lab.objects.create(
- lab_user=unh_iol,
- name="UNH_IOL",
- vlan_manager=VlanManager.objects.create(
- vlans = json.dumps(vlans),
- reserved_vlans = json.dumps(reserved),
- allow_overlapping = False,
- block_size = 20,
- ),
- api_token = Lab.make_api_token(),
- contact_email = "nfv-lab@iol.unh.edu",
- location = "University of New Hampshire, Durham NH, 03824 USA"
- )
+ lab_user=unh_iol,
+ name="UNH_IOL",
+ vlan_manager=VlanManager.objects.create(
+ vlans=json.dumps(vlans),
+ reserved_vlans=json.dumps(reserved),
+ allow_overlapping=False,
+ block_size=20,
+ ),
+ api_token=Lab.make_api_token(),
+ contact_email="nfv-lab@iol.unh.edu",
+ location="University of New Hampshire, Durham NH, 03824 USA"
+ )
return [iol]
-
def make_configurations(self):
- #scenarios
+ # scenarios
scen1 = Scenario.objects.create(name="os-nosdn-nofeature-noha")
scen2 = Scenario.objects.create(name="os-odl-kvm-ha")
scen3 = Scenario.objects.create(name="os-nosdn-nofeature-ha")
- #installers
+ # installers
fuel = Installer.objects.create(name="Fuel")
fuel.sup_scenarios.add(scen1)
fuel.sup_scenarios.add(scen3)
@@ -141,7 +145,7 @@ class Populator:
compass.sup_scenarios.add(scen3)
compass.save()
- #operating systems
+ # operating systems
ubuntu = Opsys.objects.create(name="Ubuntu")
ubuntu.sup_installers.add(compass)
ubuntu.sup_installers.add(joid)
@@ -154,61 +158,61 @@ class Populator:
suse.sup_installers.add(fuel)
suse.save()
-
- #opnfv roles
- compute = OPNFVRole.objects.create(name="Compute", description="Does the heavy lifting")
- controller = OPNFVRole.objects.create(name="Controller", description="Controls everything")
- jumphost = OPNFVRole.objects.create(name="Jumphost", description="Entry Point")
+ # opnfv roles
+ OPNFVRole.objects.create(name="Compute", description="Does the heavy lifting")
+ OPNFVRole.objects.create(name="Controller", description="Controls everything")
+ OPNFVRole.objects.create(name="Jumphost", description="Entry Point")
lab = Lab.objects.first()
user = UserProfile.objects.first().user
- image = Image.objects.create(
- lab_id=23,
- name="hpe centos",
- from_lab=lab,
- owner=user,
- host_type=HostProfile.objects.get(name="hpe")
- )
- image = Image.objects.create(
- lab_id=25,
- name="hpe ubuntu",
- from_lab=lab,
- owner=user,
- host_type=HostProfile.objects.get(name="hpe")
- )
+ Image.objects.create(
+ lab_id=23,
+ name="hpe centos",
+ from_lab=lab,
+ owner=user,
+ host_type=HostProfile.objects.get(name="hpe")
+ )
+ Image.objects.create(
+ lab_id=25,
+ name="hpe ubuntu",
+ from_lab=lab,
+ owner=user,
+ host_type=HostProfile.objects.get(name="hpe")
+ )
- image = Image.objects.create(
- lab_id=26,
- name="hpe suse",
- from_lab=lab,
- owner=user,
- host_type=HostProfile.objects.get(name="hpe")
- )
- image = Image.objects.create(
- lab_id=27,
- name="arm ubuntu",
- from_lab=lab,
- owner=user,
- host_type=HostProfile.objects.get(name="arm")
- )
+ Image.objects.create(
+ lab_id=26,
+ name="hpe suse",
+ from_lab=lab,
+ owner=user,
+ host_type=HostProfile.objects.get(name="hpe")
+ )
+
+ Image.objects.create(
+ lab_id=27,
+ name="arm ubuntu",
+ from_lab=lab,
+ owner=user,
+ host_type=HostProfile.objects.get(name="arm")
+ )
def make_lab_hosts(self, hostcount, profile, lab, data, offset=1):
for i in range(hostcount):
- name="Host_" + lab.name + "_" + profile.name + "_" + str(i + offset)
+ name = "Host_" + lab.name + "_" + profile.name + "_" + str(i + offset)
host = Host.objects.create(
- name=name,
- lab=lab,
- profile=profile,
- labid=data[i]['labid']
- )
+ name=name,
+ lab=lab,
+ profile=profile,
+ labid=data[i]['labid']
+ )
for iface_profile in profile.interfaceprofile.all():
iface_data = data[i]['interfaces'][iface_profile.name]
Interface.objects.create(
- mac_address=iface_data['mac'],
- bus_address=iface_data['bus'],
- name=iface_profile.name,
- host=host
- )
+ mac_address=iface_data['mac'],
+ bus_address=iface_data['bus'],
+ name=iface_profile.name,
+ host=host
+ )
def make_profile_data(self):
"""
@@ -219,10 +223,10 @@ class Populator:
for prof in ["hpe", "arm"]: # TODO
profile_dict = {}
host = {
- "name": prof,
- "type": 0,
- "description": "some LaaS servers"
- }
+ "name": prof,
+ "type": 0,
+ "description": "some LaaS servers"
+ }
profile_dict['host'] = host
profile_dict['interfaces'] = []
for interface in [{"name": "eno1", "speed": 1000}, {"name": "eno2", "speed": 10000}]: # TODO
@@ -277,64 +281,64 @@ class Populator:
if len(host_data_dict) < 1:
continue
host_profile = HostProfile.objects.create(
- name=host_profile_name,
- description=""
- )
+ name=host_profile_name,
+ description=""
+ )
host_profile.labs.add(lab)
example_host_data = list(host_data_dict.values())[0]
cpu_data = example_host_data['cpu']
CpuProfile.objects.create(
- cores=cpu_data['cores'],
- architecture=cpu_data['arch'],
- cpus=cpu_data['cpus'],
- host=host_profile
- )
+ cores=cpu_data['cores'],
+ architecture=cpu_data['arch'],
+ cpus=cpu_data['cpus'],
+ host=host_profile
+ )
ram_data = example_host_data['memory']
RamProfile.objects.create(
- amount=int(ram_data[:-1]),
- channels=1,
- host=host_profile
- )
+ amount=int(ram_data[:-1]),
+ channels=1,
+ host=host_profile
+ )
disks_data = example_host_data['disk']
for disk_data in disks_data:
size = 0
try:
- size=int(disk_data['size'].split('.')[0])
+ size = int(disk_data['size'].split('.')[0])
except:
- size=int(disk_data['size'].split('.')[0][:-1])
+ size = int(disk_data['size'].split('.')[0][:-1])
DiskProfile.objects.create(
- size=size,
- media_type="SSD",
- name=disk_data['name'],
- host=host_profile
- )
+ size=size,
+ media_type="SSD",
+ name=disk_data['name'],
+ host=host_profile
+ )
ifaces_data = example_host_data['interface']
for iface_data in ifaces_data:
InterfaceProfile.objects.create(
- speed=iface_data['speed'],
- name=iface_data['name'],
- host=host_profile
- )
+ speed=iface_data['speed'],
+ name=iface_data['name'],
+ host=host_profile
+ )
# all profiles created
for hostname, host_data in host_data_dict.items():
host = Host.objects.create(
- name=hostname,
- labid=hostname,
- profile=host_profile,
- lab=lab
- )
+ name=hostname,
+ labid=hostname,
+ profile=host_profile,
+ lab=lab
+ )
for iface_data in host_data['interface']:
Interface.objects.create(
- mac_address=iface_data['mac'],
- bus_address=iface_data['busaddr'],
- name=iface_data['name'],
- host=host
- )
+ mac_address=iface_data['mac'],
+ bus_address=iface_data['busaddr'],
+ name=iface_data['name'],
+ host=host
+ )
def populate(self):
self.labs = self.make_labs()
diff --git a/dashboard/src/dashboard/tasks.py b/dashboard/src/dashboard/tasks.py
index d4b4189..b1d97b7 100644
--- a/dashboard/src/dashboard/tasks.py
+++ b/dashboard/src/dashboard/tasks.py
@@ -14,7 +14,7 @@ from django.utils import timezone
from django.db.models import Q
from booking.models import Booking
from notifier.manager import NotificationHandler
-from api.models import *
+from api.models import JobStatus, SoftwareRelation, HostHardwareRelation, HostNetworkRelation, AccessRelation
from resource_inventory.resource_manager import ResourceManager
@@ -26,7 +26,7 @@ def booking_poll():
config.clear_delta()
config.set_power("off")
config.save()
- hostrelation.status=JobStatus.NEW
+ hostrelation.status = JobStatus.NEW
hostrelation.save()
def cleanup_network(qs):
@@ -53,7 +53,7 @@ def booking_poll():
interface.config.clear()
network.add_interface(interface)
network.save()
- hostrelation.status=JobStatus.NEW
+ hostrelation.status = JobStatus.NEW
hostrelation.save()
def cleanup_software(qs):
@@ -62,7 +62,7 @@ def booking_poll():
software = relation.config.opnfv
software.clear_delta()
software.save()
- relation.status=JobStatus.NEW
+ relation.status = JobStatus.NEW
relation.save()
def cleanup_access(qs):
@@ -96,11 +96,11 @@ def free_hosts():
hardware = ~Q(~Q(job__hosthardwarerelation__status=200))
bookings = Booking.objects.filter(
- networks,
- hardware,
- end__lt=timezone.now(),
- job__complete=True,
- resource__isnull=False
- )
+ networks,
+ hardware,
+ end__lt=timezone.now(),
+ job__complete=True,
+ resource__isnull=False
+ )
for booking in bookings:
ResourceManager.getInstance().deleteResourceBundle(booking.resource)
diff --git a/dashboard/src/dashboard/templatetags/__init__.py b/dashboard/src/dashboard/templatetags/__init__.py
index b5914ce..b6fef6c 100644
--- a/dashboard/src/dashboard/templatetags/__init__.py
+++ b/dashboard/src/dashboard/templatetags/__init__.py
@@ -6,5 +6,3 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-
-
diff --git a/dashboard/src/dashboard/tests/__init__.py b/dashboard/src/dashboard/tests/__init__.py
index b5914ce..b6fef6c 100644
--- a/dashboard/src/dashboard/tests/__init__.py
+++ b/dashboard/src/dashboard/tests/__init__.py
@@ -6,5 +6,3 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-
-
diff --git a/dashboard/src/dashboard/urls.py b/dashboard/src/dashboard/urls.py
index 0d7ee87..571a987 100644
--- a/dashboard/src/dashboard/urls.py
+++ b/dashboard/src/dashboard/urls.py
@@ -25,9 +25,14 @@ Including another URLconf
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
-from dashboard.views import *
+from dashboard.views import (
+ landing_view,
+ lab_list_view,
+ lab_detail_view,
+ host_profile_detail_view
+)
-app_name="dashboard"
+app_name = "dashboard"
urlpatterns = [
url(r'^$', landing_view, name='index'),
url(r'^lab/$', lab_list_view, name='all_labs'),
diff --git a/dashboard/src/dashboard/views.py b/dashboard/src/dashboard/views.py
index 2d1f8b2..36c3253 100644
--- a/dashboard/src/dashboard/views.py
+++ b/dashboard/src/dashboard/views.py
@@ -14,12 +14,11 @@ from django.views.generic import TemplateView
from django.shortcuts import render
from django.http import HttpResponseRedirect
-from booking.models import Booking
from account.models import Lab
-from resource_inventory.models import *
-from workflow.views import *
-from workflow.workflow_manager import *
+from resource_inventory.models import Image, HostProfile
+from workflow.views import create_session
+from workflow.workflow_manager import ManagerTracker
def lab_list_view(request):
@@ -40,18 +39,27 @@ def lab_detail_view(request, lab_name):
if user:
images = images | Image.objects.filter(from_lab=lab).filter(owner=user)
- return render(request, "dashboard/lab_detail.html",
- {'title': "Lab Overview",
- 'lab': lab,
- 'hostprofiles': lab.hostprofiles.all(),
- 'images': images})
+ return render(
+ request,
+ "dashboard/lab_detail.html",
+ {
+ 'title': "Lab Overview",
+ 'lab': lab,
+ 'hostprofiles': lab.hostprofiles.all(),
+ 'images': images
+ }
+ )
def host_profile_detail_view(request):
- return render(request, "dashboard/host_profile_detail.html",
- {'title': "Host Types",
- })
+ return render(
+ request,
+ "dashboard/host_profile_detail.html",
+ {
+ 'title': "Host Types",
+ }
+ )
def landing_view(request):
@@ -62,12 +70,11 @@ def landing_view(request):
try:
manager = ManagerTracker.managers[request.session['manager_session']]
-
- except KeyError as e:
+ except KeyError:
pass
if manager is not None:
- #no manager detected, don't display continue button
+ # no manager detected, don't display continue button
manager_detected = True
if request.method == 'GET':
@@ -84,7 +91,7 @@ def landing_view(request):
request.session['manager_session'] = mgr_uuid
return HttpResponseRedirect('/wf/')
- except KeyError as e:
+ except KeyError:
pass