summaryrefslogtreecommitdiffstats
path: root/dashboard/src/workflow
diff options
context:
space:
mode:
Diffstat (limited to 'dashboard/src/workflow')
-rw-r--r--dashboard/src/workflow/booking_workflow.py39
-rw-r--r--dashboard/src/workflow/forms.py161
-rw-r--r--dashboard/src/workflow/models.py52
-rw-r--r--dashboard/src/workflow/resource_bundle_workflow.py69
-rw-r--r--dashboard/src/workflow/snapshot_workflow.py11
-rw-r--r--dashboard/src/workflow/sw_bundle_workflow.py34
-rw-r--r--dashboard/src/workflow/tests/test_steps.py40
-rw-r--r--dashboard/src/workflow/tests/test_steps_render.py7
-rw-r--r--dashboard/src/workflow/tests/test_workflows.py8
-rw-r--r--dashboard/src/workflow/urls.py10
-rw-r--r--dashboard/src/workflow/views.py32
-rw-r--r--dashboard/src/workflow/workflow_factory.py55
-rw-r--r--dashboard/src/workflow/workflow_manager.py26
13 files changed, 306 insertions, 238 deletions
diff --git a/dashboard/src/workflow/booking_workflow.py b/dashboard/src/workflow/booking_workflow.py
index 213b9e6..cd12ab6 100644
--- a/dashboard/src/workflow/booking_workflow.py
+++ b/dashboard/src/workflow/booking_workflow.py
@@ -15,12 +15,12 @@ from django.utils import timezone
import json
from datetime import timedelta
-from account.models import UserProfile
from booking.models import Booking
from workflow.models import WorkflowStep
-from workflow.forms import ResourceSelectorForm, SWConfigSelectorForm, BookingMetaForm, ConfirmationForm
+from workflow.forms import ResourceSelectorForm, SWConfigSelectorForm, BookingMetaForm
from resource_inventory.models import GenericResourceBundle, ResourceBundle, ConfigBundle
+
class Resource_Select(WorkflowStep):
template = 'booking/steps/resource_select.html'
title = "Select Resource"
@@ -62,14 +62,14 @@ class Resource_Select(WorkflowStep):
edit = self.repo_get(self.repo.EDIT, False)
user = self.repo_get(self.repo.SESSION_USER)
context['form'] = ResourceSelectorForm(
- data={"user": user},
- chosen_resource=default,
- bundle=bundle,
- edit=edit
- )
+ data={"user": user},
+ chosen_resource=default,
+ bundle=bundle,
+ edit=edit
+ )
return context
- def post_render(self, request):
+ def post_render(self, request):
form = ResourceSelectorForm(request.POST)
context = self.get_context()
if form.is_valid():
@@ -86,11 +86,14 @@ class Resource_Select(WorkflowStep):
gresource_bundle = GenericResourceBundle.objects.get(id=selected_id)
except ValueError:
# we want the bundle in the repo
- gresource_bundle = self.repo_get(self.repo.GRESOURCE_BUNDLE_MODELS,{}).get("bundle", GenericResourceBundle())
+ gresource_bundle = self.repo_get(
+ self.repo.GRESOURCE_BUNDLE_MODELS,
+ {}
+ ).get("bundle", GenericResourceBundle())
self.repo_put(
- self.repo_key,
- gresource_bundle
- )
+ self.repo_key,
+ gresource_bundle
+ )
confirm = self.repo_get(self.repo.CONFIRMATION)
if self.confirm_key not in confirm:
confirm[self.confirm_key] = {}
@@ -104,6 +107,7 @@ class Resource_Select(WorkflowStep):
self.metastep.set_invalid("Please complete the fields highlighted in red to continue")
return render(request, self.template, context)
+
class Booking_Resource_Select(Resource_Select):
def __init__(self, *args, **kwargs):
@@ -119,7 +123,7 @@ class Booking_Resource_Select(Resource_Select):
try:
config_bundle = self.repo_get(self.repo.BOOKING_MODELS)['booking'].config_bundle
if default:
- return default # select created grb, even if preselected config bundle
+ return default # select created grb, even if preselected config bundle
return config_bundle.bundle
except:
pass
@@ -145,6 +149,7 @@ class Booking_Resource_Select(Resource_Select):
self.repo_put(self.repo.BOOKING_MODELS, models)
return response
+
class SWConfig_Select(WorkflowStep):
template = 'booking/steps/swconfig_select.html'
title = "Select Software Configuration"
@@ -186,7 +191,6 @@ class SWConfig_Select(WorkflowStep):
return self.render(request)
-
def get_context(self):
context = super(SWConfig_Select, self).get_context()
default = []
@@ -197,7 +201,7 @@ class SWConfig_Select(WorkflowStep):
try:
chosen_bundle = booking.config_bundle
default.append(chosen_bundle.id)
- bundle=chosen_bundle
+ bundle = chosen_bundle
except:
if created_bundle:
default.append("repo bundle")
@@ -208,6 +212,7 @@ class SWConfig_Select(WorkflowStep):
context['form'] = SWConfigSelectorForm(chosen_software=default, bundle=bundle, edit=edit, resource=grb)
return context
+
class Booking_Meta(WorkflowStep):
template = 'booking/steps/booking_meta.html'
title = "Extra Info"
@@ -231,7 +236,7 @@ class Booking_Meta(WorkflowStep):
users = models.get("collaborators", [])
for user in users:
default.append(user.id)
- except Exception as e:
+ except Exception:
pass
default_user = self.repo_get(self.repo.SESSION_USER)
@@ -271,7 +276,7 @@ class Booking_Meta(WorkflowStep):
user_data = form.cleaned_data['users']
confirm['booking']['collaborators'] = []
- user_data = user_data[2:-2] #fixes malformed string from querydict
+ user_data = user_data[2:-2] # fixes malformed string from querydict
if user_data:
form_users = json.loads(user_data)
for user_json in form_users:
diff --git a/dashboard/src/workflow/forms.py b/dashboard/src/workflow/forms.py
index d4abbc3..feb32f2 100644
--- a/dashboard/src/workflow/forms.py
+++ b/dashboard/src/workflow/forms.py
@@ -10,18 +10,20 @@
import django.forms as forms
from django.forms import widgets
-from django.contrib.auth.models import User
from django.utils.safestring import mark_safe
from django.template.loader import render_to_string
-from django.core import serializers
from django.forms.widgets import NumberInput
-from django.db.models import F
-import json
-
-from resource_inventory.models import *
from account.models import Lab
from account.models import UserProfile
+from resource_inventory.models import (
+ GenericResourceBundle,
+ ConfigBundle,
+ OPNFVRole,
+ Image,
+ Installer,
+ Scenario
+)
class SearchableSelectMultipleWidget(widgets.SelectMultiple):
@@ -47,20 +49,22 @@ class SearchableSelectMultipleWidget(widgets.SelectMultiple):
context = self.get_context(attrs)
return mark_safe(render_to_string(self.template_name, context))
- def get_context(self,attrs):
- return {'items':self.items,
- 'name':self.name,
- 'show_from_noentry':self.show_from_noentry,
- 'show_x_results':self.show_x_results,
- 'results_scrollable':self.results_scrollable,
- 'selectable_limit':self.selectable_limit,
- 'placeholder':self.placeholder,
- 'initial':self.initial,
- 'default_entry':self.default_entry,
- 'edit': self.edit,
- 'wf_type': self.wf_type
+ def get_context(self, attrs):
+ return {
+ 'items': self.items,
+ 'name': self.name,
+ 'show_from_noentry': self.show_from_noentry,
+ 'show_x_results': self.show_x_results,
+ 'results_scrollable': self.results_scrollable,
+ 'selectable_limit': self.selectable_limit,
+ 'placeholder': self.placeholder,
+ 'initial': self.initial,
+ 'default_entry': self.default_entry,
+ 'edit': self.edit,
+ 'wf_type': self.wf_type
}
+
class ResourceSelectorForm(forms.Form):
def __init__(self, data=None, **kwargs):
@@ -73,7 +77,7 @@ class ResourceSelectorForm(forms.Form):
bundle = kwargs.pop("bundle")
if "edit" in kwargs:
edit = kwargs.pop("edit")
- super(ResourceSelectorForm, self).__init__(data=data,**kwargs)
+ super(ResourceSelectorForm, self).__init__(data=data, **kwargs)
queryset = GenericResourceBundle.objects.select_related("owner").all()
if data and 'user' in data:
queryset = queryset.filter(owner=data['user'])
@@ -81,8 +85,8 @@ class ResourceSelectorForm(forms.Form):
attrs = self.build_search_widget_attrs(chosen_resource, bundle, edit, queryset)
self.fields['generic_resource_bundle'] = forms.CharField(
- widget=SearchableSelectMultipleWidget(attrs=attrs)
- )
+ widget=SearchableSelectMultipleWidget(attrs=attrs)
+ )
def build_search_widget_attrs(self, chosen_resource, bundle, edit, queryset):
resources = {}
@@ -104,7 +108,7 @@ class ResourceSelectorForm(forms.Form):
displayable['string'] = bundle.description
displayable['id'] = "repo bundle"
resources["repo bundle"] = displayable
- attrs={
+ attrs = {
'set': resources,
'show_from_noentry': "true",
'show_x_results': -1,
@@ -118,6 +122,7 @@ class ResourceSelectorForm(forms.Form):
}
return attrs
+
class SWConfigSelectorForm(forms.Form):
def __init__(self, *args, **kwargs):
@@ -134,11 +139,11 @@ class SWConfigSelectorForm(forms.Form):
edit = kwargs.pop("edit")
if "resource" in kwargs:
resource = kwargs.pop("resource")
- super(SWConfigSelectorForm, self).__init__(*args,**kwargs)
- attrs = self.build_search_widget_attrs(chosen_software,bundle, edit, resource)
+ super(SWConfigSelectorForm, self).__init__(*args, **kwargs)
+ attrs = self.build_search_widget_attrs(chosen_software, bundle, edit, resource)
self.fields['software_bundle'] = forms.CharField(
- widget=SearchableSelectMultipleWidget(attrs=attrs)
- )
+ widget=SearchableSelectMultipleWidget(attrs=attrs)
+ )
def build_search_widget_attrs(self, chosen, bundle, edit, resource):
configs = {}
@@ -162,7 +167,7 @@ class SWConfigSelectorForm(forms.Form):
displayable['id'] = "repo bundle"
configs['repo bundle'] = displayable
- attrs={
+ attrs = {
'set': configs,
'show_from_noentry': "true",
'show_x_results': -1,
@@ -176,9 +181,19 @@ class SWConfigSelectorForm(forms.Form):
}
return attrs
+
class BookingMetaForm(forms.Form):
- length = forms.IntegerField(widget=NumberInput(attrs={'type':'range', 'min':"0", "max":"21", "value":"0"}))
+ length = forms.IntegerField(
+ widget=NumberInput(
+ attrs={
+ "type": "range",
+ 'min': "0",
+ "max": "21",
+ "value": "0"
+ }
+ )
+ )
purpose = forms.CharField(max_length=1000)
project = forms.CharField(max_length=400)
info_file = forms.CharField(max_length=1000, required=False)
@@ -202,9 +217,9 @@ class BookingMetaForm(forms.Form):
self.fields['users'] = forms.CharField(
widget=SearchableSelectMultipleWidget(
attrs=self.build_search_widget_attrs(chosen_users, default_user=default_user)
- ),
+ ),
required=False
- )
+ )
def build_user_list(self):
"""
@@ -213,24 +228,24 @@ class BookingMetaForm(forms.Form):
"""
try:
users = {}
- d_qset = UserProfile.objects.select_related('user').all().exclude(user__username=self.default_user);
+ d_qset = UserProfile.objects.select_related('user').all().exclude(user__username=self.default_user)
for userprofile in d_qset:
user = {
- 'id':userprofile.user.id,
- 'expanded_name':userprofile.full_name,
- 'small_name':userprofile.user.username,
- 'string':userprofile.email_addr
- }
+ 'id': userprofile.user.id,
+ 'expanded_name': userprofile.full_name,
+ 'small_name': userprofile.user.username,
+ 'string': userprofile.email_addr
+ }
users[userprofile.user.id] = user
return users
- except Exception as e:
+ except Exception:
pass
def build_search_widget_attrs(self, chosen_users, default_user="you"):
- attrs={
+ attrs = {
'set': self.build_user_list(),
'show_from_noentry': "false",
'show_x_results': 10,
@@ -243,11 +258,12 @@ class BookingMetaForm(forms.Form):
}
return attrs
+
class MultipleSelectFilterWidget(forms.Widget):
def __init__(self, attrs=None):
super(MultipleSelectFilterWidget, self).__init__(attrs)
self.attrs = attrs
- self.template_name="dashboard/multiple_select_filter_widget.html"
+ self.template_name = "dashboard/multiple_select_filter_widget.html"
def render(self, name, value, attrs=None, renderer=None):
attrs = self.attrs
@@ -258,10 +274,12 @@ class MultipleSelectFilterWidget(forms.Widget):
def get_context(self, name, value, attrs):
return attrs
+
class MultipleSelectFilterField(forms.Field):
- def __init__( self, required=True, widget=None, label=None, initial=None,
- help_text='', error_messages=None, show_hidden_initial=False,
- validators=(), localize=False, disabled=False, label_suffix=None):
+
+ def __init__(self, required=True, widget=None, label=None, initial=None,
+ help_text='', error_messages=None, show_hidden_initial=False,
+ validators=(), localize=False, disabled=False, label_suffix=None):
"""from the documentation:
# required -- Boolean that specifies whether the field is required.
# True by default.
@@ -287,8 +305,8 @@ class MultipleSelectFilterField(forms.Field):
# label_suffix -- Suffix to be added to the label. Overrides
# form's label_suffix.
"""
- #this is bad, but django forms are annoying
- self.widget=widget
+ # this is bad, but django forms are annoying
+ self.widget = widget
if self.widget is None:
self.widget = MultipleSelectFilterWidget()
super(MultipleSelectFilterField, self).__init__(
@@ -311,6 +329,7 @@ class MultipleSelectFilterField(forms.Field):
"""
return data
+
class FormUtils:
@staticmethod
def getLabData():
@@ -355,12 +374,13 @@ class FormUtils:
filter_objects = [("labs", labs.values()), ("hosts", hosts.values())]
context = {
- 'filter_objects': filter_objects,
- 'mapping': mapping,
- 'items': items
- }
+ 'filter_objects': filter_objects,
+ 'mapping': mapping,
+ 'items': items
+ }
return context
+
class HardwareDefinitionForm(forms.Form):
def __init__(self, *args, **kwargs):
@@ -369,38 +389,40 @@ class HardwareDefinitionForm(forms.Form):
attrs = FormUtils.getLabData()
attrs['selection_data'] = selection_data
self.fields['filter_field'] = MultipleSelectFilterField(
- widget=MultipleSelectFilterWidget(
- attrs=attrs
- )
- )
+ widget=MultipleSelectFilterWidget(
+ attrs=attrs
+ )
+ )
+
class PodDefinitionForm(forms.Form):
- fields = [ "xml" ]
+ fields = ["xml"]
xml = forms.CharField()
+
class ResourceMetaForm(forms.Form):
bundle_name = forms.CharField(label="POD Name")
bundle_description = forms.CharField(label="POD Description", widget=forms.Textarea)
+
class GenericHostMetaForm(forms.Form):
host_profile = forms.CharField(label="Host Type", disabled=True, required=False)
host_name = forms.CharField(label="Host Name")
+
class NetworkDefinitionForm(forms.Form):
def __init__(self, *args, **kwargs):
- fields = []
-
super(NetworkDefinitionForm, self).__init__(**kwargs)
+
class NetworkConfigurationForm(forms.Form):
def __init__(self, *args, **kwargs):
- fields = []
-
super(NetworkConfigurationForm).__init__(**kwargs)
+
class HostSoftwareDefinitionForm(forms.Form):
fields = ["host_name", "role", "image"]
@@ -408,6 +430,7 @@ class HostSoftwareDefinitionForm(forms.Form):
role = forms.ModelChoiceField(queryset=OPNFVRole.objects.all())
image = forms.ModelChoiceField(queryset=Image.objects.all())
+
class SoftwareConfigurationForm(forms.Form):
name = forms.CharField(max_length=200)
@@ -416,31 +439,39 @@ class SoftwareConfigurationForm(forms.Form):
installer = forms.ModelChoiceField(queryset=Installer.objects.all(), disabled=True, required=False)
scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), disabled=True, required=False)
+
class WorkflowSelectionForm(forms.Form):
fields = ['workflow']
empty_permitted = False
- workflow = forms.ChoiceField( choices=(
- (0, 'Booking'),
- (1, 'Resource Bundle'),
- (2, 'Software Configuration')
+ workflow = forms.ChoiceField(
+ choices=(
+ (0, 'Booking'),
+ (1, 'Resource Bundle'),
+ (2, 'Software Configuration')
),
label="Choose Workflow",
initial='booking',
- required=True)
+ required=True
+ )
+
class SnapshotHostSelectForm(forms.Form):
host = forms.CharField()
+
class SnapshotMetaForm(forms.Form):
name = forms.CharField()
description = forms.CharField()
+
class ConfirmationForm(forms.Form):
fields = ['confirm']
- confirm = forms.ChoiceField( choices=(
- (True, "Confirm"),
- (False, "Cancel"))
+ confirm = forms.ChoiceField(
+ choices=(
+ (True, "Confirm"),
+ (False, "Cancel")
)
+ )
diff --git a/dashboard/src/workflow/models.py b/dashboard/src/workflow/models.py
index e5a23b2..966582c 100644
--- a/dashboard/src/workflow/models.py
+++ b/dashboard/src/workflow/models.py
@@ -8,8 +8,6 @@
##############################################################################
-from django.contrib.auth.models import User
-from django.db import models
from django.shortcuts import render
from django.contrib import messages
@@ -17,11 +15,12 @@ import yaml
import requests
from workflow.forms import ConfirmationForm
-from api.models import *
-from dashboard.exceptions import *
-from resource_inventory.models import *
+from api.models import JobFactory
+from dashboard.exceptions import ResourceAvailabilityException, ModelValidationException
+from resource_inventory.models import Image, GenericInterface
from resource_inventory.resource_manager import ResourceManager
from notifier.manager import NotificationHandler
+from booking.models import Booking
class BookingAuthManager():
@@ -52,10 +51,9 @@ class BookingAuthManager():
return None
return ptl
- except Exception as e:
+ except Exception:
return None
-
def booking_allowed(self, booking, repo):
"""
This is the method that will have to change whenever the booking policy changes in the Infra
@@ -64,14 +62,13 @@ class BookingAuthManager():
which is checked using the provided info file
"""
if len(booking.resource.template.getHosts()) < 2:
- return True #if they only have one server, we dont care
+ return True # if they only have one server, we dont care
if booking.owner.userprofile.booking_privledge:
return True # admin override for this user
if repo.BOOKING_INFO_FILE not in repo.el:
return False # INFO file not provided
ptl_info = self.parse_url(repo.BOOKING_INFO_FILE)
- return ptl_info and ptl_info == booking.owner.userprofile.email_addr
-
+ return ptl_info and ptl_info == booking.owner.userprofile.email_addr
class WorkflowStep(object):
@@ -116,6 +113,7 @@ class WorkflowStep(object):
def repo_put(self, key, value):
return self.repo.put(key, value, self.id)
+
class Confirmation_Step(WorkflowStep):
template = 'workflow/confirm.html'
title = "Confirm Changes"
@@ -140,14 +138,13 @@ class Confirmation_Step(WorkflowStep):
return 1 # There is a problem with these vlans
return 0
-
def get_context(self):
context = super(Confirmation_Step, self).get_context()
context['form'] = ConfirmationForm()
context['confirmation_info'] = yaml.dump(
- self.repo_get(self.repo.CONFIRMATION),
- default_flow_style=False
- ).strip()
+ self.repo_get(self.repo.CONFIRMATION),
+ default_flow_style=False
+ ).strip()
context['vlan_warning'] = self.get_vlan_warning()
return context
@@ -211,6 +208,7 @@ class Workflow():
steps = []
active_index = 0
+
class Repository():
EDIT = "editing"
@@ -240,12 +238,11 @@ class Repository():
SNAPSHOT_DESC = "description of the snapshot"
BOOKING_INFO_FILE = "the INFO.yaml file for this user's booking"
-
def get(self, key, default, id):
self.add_get_history(key, id)
return self.el.get(key, default)
- def put(self,key,val, id):
+ def put(self, key, val, id):
self.add_put_history(key, id)
self.el[key] = val
@@ -256,7 +253,7 @@ class Repository():
self.add_history(key, id, self.put_history)
def add_history(self, key, id, history):
- if not key in history:
+ if key not in history:
history[key] = [id]
else:
history[key].append(id)
@@ -266,7 +263,7 @@ class Repository():
errors = self.make_snapshot()
if errors:
return errors
- #if GRB WF, create it
+ # if GRB WF, create it
if self.GRESOURCE_BUNDLE_MODELS in self.el:
errors = self.make_generic_resource_bundle()
if errors:
@@ -285,7 +282,6 @@ class Repository():
booking = self.el[self.BOOKING_MODELS]['booking']
NotificationHandler.notify_new_booking(booking)
-
def make_snapshot(self):
owner = self.el[self.SESSION_USER]
models = self.el[self.SNAPSHOT_MODELS]
@@ -310,7 +306,6 @@ class Repository():
image.host_type = host.profile
image.save()
-
def make_generic_resource_bundle(self):
owner = self.el[self.SESSION_USER]
if self.GRESOURCE_BUNDLE_MODELS in self.el:
@@ -354,10 +349,10 @@ class Repository():
for resource_name, mapping in models['vlans'].items():
for profile_name, vlan_set in mapping.items():
interface = GenericInterface.objects.get(
- profile__name=profile_name,
- host__resource__name=resource_name,
- host__resource__bundle=models['bundle']
- )
+ profile__name=profile_name,
+ host__resource__name=resource_name,
+ host__resource__bundle=models['bundle']
+ )
for vlan in vlan_set:
try:
vlan.save()
@@ -367,16 +362,13 @@ class Repository():
else:
return "GRB, no vlan set provided. CODE:0x0018"
-
else:
return "GRB no models given. CODE:0x0001"
self.el[self.VALIDATED_MODEL_GRB] = bundle
return False
-
def make_software_config_bundle(self):
- owner = self.el[self.SESSION_USER]
models = self.el[self.CONFIG_MODELS]
if 'bundle' in models:
bundle = models['bundle']
@@ -402,7 +394,7 @@ class Repository():
if 'opnfv' in models:
opnfvconfig = models['opnfv']
opnfvconfig.bundle = opnfvconfig.bundle
- if not opnfvconfig.scenario in opnfvconfig.installer.sup_scenarios.all():
+ if opnfvconfig.scenario not in opnfvconfig.installer.sup_scenarios.all():
return "SWC, scenario not supported by installer. CODE:0x000d"
try:
opnfvconfig.save()
@@ -414,7 +406,6 @@ class Repository():
self.el[self.VALIDATED_MODEL_CONFIG] = bundle
return False
-
def make_booking(self):
models = self.el[self.BOOKING_MODELS]
owner = self.el[self.SESSION_USER]
@@ -498,10 +489,9 @@ class Repository():
vlan_manager.reserve_vlans(vlans)
vlan_manager.reserve_public_vlan(public_vlan.vlan_id)
return True
- except Exception as e:
+ except Exception:
return False
-
def __init__(self):
self.el = {}
self.el[self.CONFIRMATION] = {}
diff --git a/dashboard/src/workflow/resource_bundle_workflow.py b/dashboard/src/workflow/resource_bundle_workflow.py
index 63ce3bd..9fb4ae1 100644
--- a/dashboard/src/workflow/resource_bundle_workflow.py
+++ b/dashboard/src/workflow/resource_bundle_workflow.py
@@ -16,9 +16,27 @@ import re
from xml.dom import minidom
from workflow.models import WorkflowStep
-from workflow.forms import *
-from resource_inventory.models import *
-from dashboard.exceptions import *
+from account.models import Lab
+from workflow.forms import (
+ HardwareDefinitionForm,
+ NetworkDefinitionForm,
+ ResourceMetaForm,
+ GenericHostMetaForm
+)
+from resource_inventory.models import (
+ GenericResourceBundle,
+ Vlan,
+ GenericInterface,
+ GenericHost,
+ GenericResource,
+ HostProfile
+)
+from dashboard.exceptions import (
+ InvalidVlanConfigurationException,
+ NetworkExistsException,
+ InvalidHostnameException,
+ NonUniqueHostnameException
+)
import logging
logger = logging.getLogger(__name__)
@@ -30,6 +48,7 @@ class Define_Hardware(WorkflowStep):
title = "Define Hardware"
description = "Choose the type and amount of machines you want"
short_title = "hosts"
+
def get_context(self):
context = super(Define_Hardware, self).get_context()
selection_data = {"hosts": {}, "labs": {}}
@@ -45,8 +64,8 @@ class Define_Hardware(WorkflowStep):
selection_data['labs'] = {"lab_" + str(models.get("bundle").lab.lab_user.id): "true"}
form = HardwareDefinitionForm(
- selection_data=selection_data
- )
+ selection_data=selection_data
+ )
context['form'] = form
return context
@@ -54,7 +73,6 @@ class Define_Hardware(WorkflowStep):
self.context = self.get_context()
return render(request, self.template, self.context)
-
def update_models(self, data):
data = json.loads(data['filter_field'])
models = self.repo_get(self.repo.GRESOURCE_BUNDLE_MODELS, {})
@@ -90,12 +108,11 @@ class Define_Hardware(WorkflowStep):
if list(lab_dict.values())[0]: # True for lab the user selected
lab_user_id = int(list(lab_dict.keys())[0].split("_")[-1])
models['bundle'].lab = Lab.objects.get(lab_user__id=lab_user_id)
- break # if somehow we get two 'true' labs, we only use one
+ break # if somehow we get two 'true' labs, we only use one
# return to repo
self.repo_put(self.repo.GRESOURCE_BUNDLE_MODELS, models)
-
def update_confirmation(self):
confirm = self.repo_get(self.repo.CONFIRMATION, {})
if "resource" not in confirm:
@@ -109,7 +126,6 @@ class Define_Hardware(WorkflowStep):
confirm['resource']['lab'] = models['lab'].lab_user.username
self.repo_put(self.repo.CONFIRMATION, confirm)
-
def post_render(self, request):
try:
self.form = HardwareDefinitionForm(request.POST)
@@ -125,6 +141,7 @@ class Define_Hardware(WorkflowStep):
self.context = self.get_context()
return render(request, self.template, self.context)
+
class Define_Nets(WorkflowStep):
template = 'resource/steps/pod_definition.html'
title = "Define Networks"
@@ -147,7 +164,7 @@ class Define_Nets(WorkflowStep):
vlans = lab.vlan_manager.get_vlan(count=lab.vlan_manager.block_size)
self.repo_put(self.repo.VLANS, vlans)
return vlans
- except Exception as e:
+ except Exception:
return None
def get_context(self):
@@ -165,7 +182,7 @@ class Define_Nets(WorkflowStep):
added_list = []
added_dict = {}
context['added_hosts'] = []
- if not hostlist is None:
+ if hostlist is not None:
new_hostlist = []
for host in models['hosts']:
intcount = host.profile.interfaceprofile.count()
@@ -181,9 +198,12 @@ class Define_Nets(WorkflowStep):
host['id'] = generic_host.resource.name
host['interfaces'] = []
for iface in host_profile.interfaceprofile.all():
- host['interfaces'].append({
+ host['interfaces'].append(
+ {
"name": iface.name,
- "description": "speed: " + str(iface.speed) + "M\ntype: " + iface.nic_type})
+ "description": "speed: " + str(iface.speed) + "M\ntype: " + iface.nic_type
+ }
+ )
host['value'] = {"name": generic_host.resource.name}
host['value']['description'] = generic_host.profile.description
context['hosts'].append(json.dumps(host))
@@ -195,8 +215,9 @@ class Define_Nets(WorkflowStep):
else:
context['xml'] = False
- except Exception as e:
+ except Exception:
pass
+
return context
def post_render(self, request):
@@ -212,7 +233,7 @@ class Define_Nets(WorkflowStep):
self.updateModels(xmlData)
# update model with xml
self.metastep.set_valid("Networks applied successfully")
- except Exception as e:
+ except Exception:
self.metastep.set_invalid("An error occurred when applying networks")
return self.render(request)
@@ -222,7 +243,7 @@ class Define_Nets(WorkflowStep):
given_hosts, interfaces = self.parseXml(xmlData)
vlan_manager = models['bundle'].lab.vlan_manager
existing_host_list = models.get("hosts", [])
- existing_hosts = {} # maps id to host
+ existing_hosts = {} # maps id to host
for host in existing_host_list:
existing_hosts[host.resource.name] = host
@@ -233,7 +254,6 @@ class Define_Nets(WorkflowStep):
for ifaceId in given_host['interfaces']:
iface = interfaces[ifaceId]
- iface_profile = existing_host.profile.interfaceprofile.get(name=iface['profile_name'])
if existing_host.resource.name not in models['vlans']:
models['vlans'][existing_host.resource.name] = {}
models['vlans'][existing_host.resource.name][iface['profile_name']] = []
@@ -255,14 +275,13 @@ class Define_Nets(WorkflowStep):
interfaces = {} # maps id -> interface
xmlDom = minidom.parseString(xmlString)
root = xmlDom.documentElement.firstChild
- connections = []
netids = {}
untagged_ints = {}
for cell in root.childNodes:
cellId = cell.getAttribute('id')
if cell.getAttribute("edge"):
- #cell is a network connection
+ # cell is a network connection
escaped_json_str = cell.getAttribute("value")
json_str = escaped_json_str.replace('&quot;', '"')
attributes = json.loads(json_str)
@@ -272,15 +291,15 @@ class Define_Nets(WorkflowStep):
src = cell.getAttribute("source")
tgt = cell.getAttribute("target")
if src in parent_nets:
- #src is a network port
+ # src is a network port
network = networks[parent_nets[src]]
- if tgt in untagged_ints and tagged==False:
+ if tgt in untagged_ints and not tagged:
raise InvalidVlanConfigurationException("More than one untagged vlan on an interface")
interface = interfaces[tgt]
untagged_ints[tgt] = True
else:
network = networks[parent_nets[tgt]]
- if src in untagged_ints and tagged==False:
+ if src in untagged_ints and not tagged:
raise InvalidVlanConfigurationException("More than one untagged vlan on an interface")
interface = interfaces[src]
untagged_ints[src] = True
@@ -296,7 +315,7 @@ class Define_Nets(WorkflowStep):
int_netid = int(nid)
assert public or int_netid > 1, "Net id is 1 or lower"
assert int_netid < 4095, "Net id is 4095 or greater"
- except Exception as e:
+ except Exception:
raise InvalidVlanConfigurationException("VLAN ID is not an integer more than 1 and less than 4095")
if nid in netids:
raise NetworkExistsException("Non unique network id found")
@@ -307,7 +326,7 @@ class Define_Nets(WorkflowStep):
networks[cellId] = network
elif "host" in cellId: # cell is a host/machine
- #TODO gather host info
+ # TODO gather host info
cell_json_str = cell.getAttribute("value")
cell_json = json.loads(cell_json_str)
host = {"interfaces": [], "name": cellId, "profile_name": cell_json['name']}
@@ -318,7 +337,7 @@ class Define_Nets(WorkflowStep):
if "network" in parentId:
parent_nets[cellId] = parentId
elif "host" in parentId:
- #TODO gather iface info
+ # TODO gather iface info
cell_json_str = cell.getAttribute("value")
cell_json = json.loads(cell_json_str)
iface = {"name": cellId, "networks": [], "profile_name": cell_json['name']}
diff --git a/dashboard/src/workflow/snapshot_workflow.py b/dashboard/src/workflow/snapshot_workflow.py
index 9d4b880..4ddc397 100644
--- a/dashboard/src/workflow/snapshot_workflow.py
+++ b/dashboard/src/workflow/snapshot_workflow.py
@@ -11,9 +11,11 @@
import datetime
import json
-from resource_inventory.models import *
-from workflow.models import *
-from workflow.forms import *
+from booking.models import Booking
+from resource_inventory.models import Host, Image
+from workflow.models import WorkflowStep
+from workflow.forms import SnapshotMetaForm, SnapshotHostSelectForm
+
class Select_Host_Step(WorkflowStep):
template = "snapshot_workflow/steps/select_host.html"
@@ -37,7 +39,6 @@ class Select_Host_Step(WorkflowStep):
for genericHost in booking.resource.template.getHosts():
booking_hosts[booking.id]['hosts'].append({"name": genericHost.resource.name})
-
context['booking_hosts'] = booking_hosts
chosen_host = self.repo_get(self.repo.SNAPSHOT_MODELS, {}).get("host")
@@ -77,6 +78,7 @@ class Select_Host_Step(WorkflowStep):
self.metastep.set_valid("Success")
return self.render(request)
+
class Image_Meta_Step(WorkflowStep):
template = "snapshot_workflow/steps/meta.html"
title = "Additional Information"
@@ -88,7 +90,6 @@ class Image_Meta_Step(WorkflowStep):
context['form'] = SnapshotMetaForm()
return context
-
def post_render(self, request):
form = SnapshotMetaForm(request.POST)
if form.is_valid():
diff --git a/dashboard/src/workflow/sw_bundle_workflow.py b/dashboard/src/workflow/sw_bundle_workflow.py
index 0e9be95..56d0a5d 100644
--- a/dashboard/src/workflow/sw_bundle_workflow.py
+++ b/dashboard/src/workflow/sw_bundle_workflow.py
@@ -8,18 +8,15 @@
##############################################################################
-from django.forms import formset_factory, modelformset_factory
+from django.forms import formset_factory
from workflow.models import WorkflowStep
from workflow.forms import SoftwareConfigurationForm, HostSoftwareDefinitionForm
from workflow.booking_workflow import Resource_Select
-from resource_inventory.models import *
+from resource_inventory.models import Image, GenericHost, ConfigBundle, HostConfiguration, Installer, OPNFVConfig
-#resource selection step is reused from Booking workflow
-
-#TODO: change this: too hacky, just for presentation
-
+# resource selection step is reused from Booking workflow
class SWConf_Resource_Select(Resource_Select):
def __init__(self, *args, **kwargs):
super(SWConf_Resource_Select, self).__init__(*args, **kwargs)
@@ -42,6 +39,7 @@ class SWConf_Resource_Select(Resource_Select):
self.repo_put(self.repo.CONFIG_MODELS, models)
return response
+
class Define_Software(WorkflowStep):
template = 'config_bundle/steps/define_software.html'
title = "Pick Software"
@@ -69,7 +67,7 @@ class Define_Software(WorkflowStep):
filter_data = {}
user = self.repo_get(self.repo.SESSION_USER)
- i=0;
+ i = 0
for host_data in hosts_initial:
host = GenericHost.objects.get(pk=host_data['host_id'])
excluded_images = Image.objects.exclude(owner=user).exclude(public=True)
@@ -143,10 +141,10 @@ class Define_Software(WorkflowStep):
role = form.cleaned_data['role']
bundle = models['bundle']
hostConfig = HostConfiguration(
- host=host,
- image=image,
- bundle=bundle,
- opnfvRole=role
+ host=host,
+ image=image,
+ bundle=bundle,
+ opnfvRole=role
)
models['host_configs'].append(hostConfig)
confirm_host = {"name": host.resource.name, "image": image.name, "role": role.name}
@@ -163,10 +161,11 @@ class Define_Software(WorkflowStep):
return self.render(request)
+
class Config_Software(WorkflowStep):
template = 'config_bundle/steps/config_software.html'
form = SoftwareConfigurationForm
- context = {'workspace_form':form}
+ context = {'workspace_form': form}
title = "Other Info"
description = "Give your software config a name, description, and other stuff"
short_title = "config info"
@@ -203,7 +202,6 @@ class Config_Software(WorkflowStep):
if "bundle" not in models:
models['bundle'] = ConfigBundle(owner=self.repo_get(self.repo.SESSION_USER))
-
confirm = self.repo_get(self.repo.CONFIRMATION, {})
if "configuration" not in confirm:
confirm['configuration'] = {}
@@ -216,10 +214,10 @@ class Config_Software(WorkflowStep):
installer = form.cleaned_data['installer']
scenario = form.cleaned_data['scenario']
opnfv = OPNFVConfig(
- bundle=models['bundle'],
- installer=installer,
- scenario=scenario
- )
+ bundle=models['bundle'],
+ installer=installer,
+ scenario=scenario
+ )
models['opnfv'] = opnfv
confirm['configuration']['installer'] = form.cleaned_data['installer'].name
confirm['configuration']['scenario'] = form.cleaned_data['scenario'].name
@@ -233,6 +231,6 @@ class Config_Software(WorkflowStep):
self.repo_put(self.repo.CONFIG_MODELS, models)
self.repo_put(self.repo.CONFIRMATION, confirm)
- except Exception as e:
+ except Exception:
pass
return self.render(request)
diff --git a/dashboard/src/workflow/tests/test_steps.py b/dashboard/src/workflow/tests/test_steps.py
index 602d3dd..380102a 100644
--- a/dashboard/src/workflow/tests/test_steps.py
+++ b/dashboard/src/workflow/tests/test_steps.py
@@ -6,18 +6,28 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from django.test import TestCase, client
+
+from django.test import TestCase
from dashboard.populate_db import Populator
from workflow.tests import constants
from workflow.workflow_factory import WorkflowFactory
from workflow.models import Repository
-from workflow.resource_bundle_workflow import *
-from workflow.sw_bundle_workflow import *
-from workflow.booking_workflow import *
+from workflow.resource_bundle_workflow import Define_Hardware, Define_Nets, Resource_Meta_Info, Host_Meta_Info
+from workflow.sw_bundle_workflow import SWConf_Resource_Select, Define_Software, Config_Software
+from workflow.booking_workflow import Booking_Resource_Select, SWConfig_Select, Booking_Meta
from django.http import QueryDict, HttpRequest
from django.contrib.auth.models import User
-from django.core.management import call_command
-from resource_inventory.models import *
+from resource_inventory.models import (
+ Scenario,
+ Installer,
+ OPNFVRole,
+ Image,
+ GenericResourceBundle,
+ GenericHost,
+ HostProfile,
+ GenericResource,
+ ConfigBundle
+)
class BaseStepTestCase(TestCase):
@@ -48,7 +58,7 @@ class BookingResourceSelectTestCase(BaseStepTestCase):
grb_model = GenericResourceBundle.objects.filter(owner__username="user 1").first()
grb = [{"small_name": grb_model.name, "expanded_name": "user 1", "id": grb_model.id, "string": ""}]
grb = str(grb).replace("'", '"')
- data = {"generic_resource_bundle": grb }
+ data = {"generic_resource_bundle": grb}
response, context = self.step_test(Booking_Resource_Select, data)
self.assertTrue(True)
@@ -60,11 +70,12 @@ class BookingResourceSelectTestCase(BaseStepTestCase):
data = {}
response, context = self.step_test(SWConfig_Select, data)
+
class SoftwareConfigSelectTestCase(BaseStepTestCase):
def test_step_with_good_data(self):
config_model = ConfigBundle.objects.filter(owner__username="user 1").first()
- config = [{"expanded_name":"user 1", "small_name":config_model.name, "id":config_model.id, "string":""}]
+ config = [{"expanded_name": "user 1", "small_name": config_model.name, "id": config_model.id, "string": ""}]
config = str(config).replace("'", '"')
data = {"software_bundle": config}
response, context = self.step_test(SWConfig_Select, data)
@@ -77,6 +88,7 @@ class SoftwareConfigSelectTestCase(BaseStepTestCase):
data = {}
response, context = self.step_test(SWConfig_Select, data)
+
class BookingMetaTestCase(BaseStepTestCase):
def test_step_with_good_data(self):
@@ -84,9 +96,9 @@ class BookingMetaTestCase(BaseStepTestCase):
user2 = User.objects.get(username="user 2")
john = User.objects.get(username="johnsmith")
users = [
- {"expanded_name":"", "id":user2.id, "small_name":user2.username, "string":user2.email},
- {"expanded_name":"", "id":john.id, "small_name":john.username, "string":john.email}
- ]
+ {"expanded_name": "", "id": user2.id, "small_name": user2.username, "string": user2.email},
+ {"expanded_name": "", "id": john.id, "small_name": john.username, "string": john.email}
+ ]
users = str(users).replace("'", '"')
data['users'] = users
response, context = self.step_test(Booking_Meta, data)
@@ -104,7 +116,7 @@ class DefineHardwareTestCase(BaseStepTestCase):
def test_step_with_good_data(self):
hosts = {"host_4": 1, "host_1": 1}
- labs = {"lab_1":"true"}
+ labs = {"lab_1": "true"}
data = {"hosts": hosts, "labs": labs}
response, context = self.step_test(Define_Hardware, data)
@@ -197,7 +209,7 @@ class SWConfResourceSelectTestCase(BaseStepTestCase):
grb_model = GenericResourceBundle.objects.filter(owner__username="user 1").first()
grb = [{"small_name": grb_model.name, "expanded_name": "user 1", "id": grb_model.id, "string": ""}]
grb = str(grb).replace("'", '"')
- data = {"generic_resource_bundle": grb }
+ data = {"generic_resource_bundle": grb}
response, context = self.step_test(SWConf_Resource_Select, data)
def test_step_with_bad_data(self): # TODO
@@ -220,7 +232,6 @@ class DefineSoftwareTestCase(BaseStepTestCase):
repo.el[repo.SWCONF_SELECTED_GRB] = grb
return repo
-
def test_step_with_good_data(self):
data = {"form-INITIAL_FORMS": 3, "form-MAX_NUM_FORMS": 1000}
data["form-MIN_NUM_FORMS"] = 0
@@ -268,4 +279,3 @@ class ConfigSoftwareTestCase(BaseStepTestCase):
def test_step_with_empty_data(self):
data = {}
response, context = self.step_test(Config_Software, data)
-
diff --git a/dashboard/src/workflow/tests/test_steps_render.py b/dashboard/src/workflow/tests/test_steps_render.py
index 3da3b3d..f3df8f2 100644
--- a/dashboard/src/workflow/tests/test_steps_render.py
+++ b/dashboard/src/workflow/tests/test_steps_render.py
@@ -6,8 +6,10 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
from django.test import TestCase, Client
+
class SuperViewTestCase(TestCase):
url = "/"
client = Client()
@@ -20,17 +22,22 @@ class SuperViewTestCase(TestCase):
class DefineHardwareViewTestCase(SuperViewTestCase):
url = "/wf/workflow/step/define_hardware"
+
class DefineNetworkViewTestCase(SuperViewTestCase):
url = "/wf/workflow/step/define_net"
+
class ResourceMetaViewTestCase(SuperViewTestCase):
url = "/wf/workflow/step/resource_meta"
+
class BookingMetaViewTestCase(SuperViewTestCase):
url = "/wf/workflow/step/booking_meta"
+
class SoftwareSelectViewTestCase(SuperViewTestCase):
url = "/wf/workflow/step/software_select"
+
class ResourceSelectViewTestCase(SuperViewTestCase):
url = "/wf/workflow/step/resource_select"
diff --git a/dashboard/src/workflow/tests/test_workflows.py b/dashboard/src/workflow/tests/test_workflows.py
index 71d0144..7a53521 100644
--- a/dashboard/src/workflow/tests/test_workflows.py
+++ b/dashboard/src/workflow/tests/test_workflows.py
@@ -6,10 +6,10 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from django.test import TestCase, client
+
+from django.test import TestCase
from workflow.workflow_factory import WorkflowFactory
from dashboard.populate_db import Populator
-from resource_inventory.models import *
"""
@@ -25,6 +25,7 @@ To remove a workflow:
POST to /wf/workflow {"cancel": ""}
"""
+
class WorkflowTestCase(TestCase):
@classmethod
@@ -62,6 +63,7 @@ class WorkflowTestCase(TestCase):
self.assertIsNone(exception)
+
class BookingWorkflowTestCase(WorkflowTestCase):
@classmethod
@@ -73,6 +75,7 @@ class BookingWorkflowTestCase(WorkflowTestCase):
def test_steps_render(self):
super(BookingWorkflowTestCase, self).render_steps()
+
class ResourceWorkflowTestCase(WorkflowTestCase):
@classmethod
@@ -84,6 +87,7 @@ class ResourceWorkflowTestCase(WorkflowTestCase):
def test_steps_render(self):
super(ResourceWorkflowTestCase, self).render_steps()
+
class ConfigWorkflowTestCase(WorkflowTestCase):
@classmethod
diff --git a/dashboard/src/workflow/urls.py b/dashboard/src/workflow/urls.py
index c7f8acb..b131d84 100644
--- a/dashboard/src/workflow/urls.py
+++ b/dashboard/src/workflow/urls.py
@@ -8,13 +8,13 @@
##############################################################################
-from django.conf.urls import url, include
+from django.conf.urls import url
from django.conf import settings
-from workflow.views import *
-from workflow.models import *
-from workflow.resource_bundle_workflow import *
-from workflow.booking_workflow import *
+from workflow.views import step_view, delete_session, manager_view, viewport_view
+from workflow.models import Repository
+from workflow.resource_bundle_workflow import Define_Hardware, Define_Nets, Resource_Meta_Info
+from workflow.booking_workflow import SWConfig_Select, Resource_Select, Booking_Meta
app_name = 'workflow'
urlpatterns = [
diff --git a/dashboard/src/workflow/views.py b/dashboard/src/workflow/views.py
index 85e4eac..e5ef5c6 100644
--- a/dashboard/src/workflow/views.py
+++ b/dashboard/src/workflow/views.py
@@ -8,15 +8,12 @@
##############################################################################
-from django.http import HttpResponse, HttpRequest, HttpResponseGone
-from django.urls import reverse
-from django.shortcuts import render, redirect
-from django import forms
+from django.http import HttpResponse, HttpResponseGone
+from django.shortcuts import render
import uuid
-from workflow.forms import *
-from workflow.workflow_manager import *
+from workflow.workflow_manager import ManagerTracker, SessionManager
import logging
logger = logging.getLogger(__name__)
@@ -31,32 +28,35 @@ def attempt_auth(request):
except KeyError:
return None
+
def delete_session(request):
try:
- manager = ManagerTracker.managers[request.session['manager_session']]
del ManagerTracker.managers[request.session['manager_session']]
return HttpResponse('')
- except KeyError:
+ except Exception:
return None
+
def step_view(request):
manager = attempt_auth(request)
if not manager:
- #no manager found, redirect to "lost" page
+ # no manager found, redirect to "lost" page
return no_workflow(request)
if request.GET.get('step') is not None:
manager.goto(int(request.GET.get('step')))
return manager.render(request)
+
def manager_view(request):
manager = attempt_auth(request)
if not manager:
return HttpResponseGone("No session found that relates to current request")
- if request.method == 'GET': #no need for this statement if only intercepting post requests
+ if request.method == 'GET':
+ # no need for this statement if only intercepting post requests
- #return general context for viewport page
+ # return general context for viewport page
return manager.status(request)
if request.method == 'POST':
@@ -64,18 +64,17 @@ def manager_view(request):
logger.debug("add found")
target_id = None
if 'target' in request.POST:
- target_id=int(request.POST.get('target'))
+ target_id = int(request.POST.get('target'))
manager.add_workflow(workflow_type=int(request.POST.get('add')), target_id=target_id)
elif request.POST.get('edit') is not None and request.POST.get('edit_id') is not None:
logger.debug("edit found")
manager.add_workflow(workflow_type=request.POST.get('edit'), edit_object=int(request.POST.get('edit_id')))
elif request.POST.get('cancel') is not None:
- mgr = ManagerTracker.managers[request.session['manager_session']]
del ManagerTracker.managers[request.session['manager_session']]
- del mgr
return manager.status(request)
+
def viewport_view(request):
if not request.user.is_authenticated:
return login(request)
@@ -84,11 +83,12 @@ def viewport_view(request):
if manager is None:
return no_workflow(request)
- if request.method == 'GET':
+ if request.method == 'GET':
return render(request, 'workflow/viewport-base.html')
else:
pass
+
def create_session(wf_type, request):
wf = int(wf_type)
smgr = SessionManager(request=request)
@@ -98,11 +98,13 @@ def create_session(wf_type, request):
return manager_uuid
+
def no_workflow(request):
logger.debug("There is no active workflow")
return render(request, 'workflow/no_workflow.html', {'title': "Not Found"})
+
def login(request):
return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
diff --git a/dashboard/src/workflow/workflow_factory.py b/dashboard/src/workflow/workflow_factory.py
index 7c0dcb9..9a42d86 100644
--- a/dashboard/src/workflow/workflow_factory.py
+++ b/dashboard/src/workflow/workflow_factory.py
@@ -8,30 +8,33 @@
##############################################################################
-from workflow.booking_workflow import *
-from workflow.resource_bundle_workflow import *
-from workflow.sw_bundle_workflow import *
-from workflow.snapshot_workflow import *
-from workflow.models import Workflow, Repository
+from workflow.booking_workflow import Booking_Resource_Select, SWConfig_Select, Booking_Meta
+from workflow.resource_bundle_workflow import Define_Hardware, Define_Nets, Resource_Meta_Info
+from workflow.sw_bundle_workflow import Config_Software, Define_Software, SWConf_Resource_Select
+from workflow.snapshot_workflow import Select_Host_Step, Image_Meta_Step
import uuid
import logging
logger = logging.getLogger(__name__)
+
class BookingMetaWorkflow(object):
workflow_type = 0
color = "#0099ff"
is_child = False
+
class ResourceMetaWorkflow(object):
workflow_type = 1
color = "#ff6600"
+
class ConfigMetaWorkflow(object):
workflow_type = 2
color = "#00ffcc"
+
class MetaRelation(object):
def __init__(self, *args, **kwargs):
self.color = "#cccccc"
@@ -47,8 +50,8 @@ class MetaRelation(object):
'depth': self.depth,
}
+
class MetaStep(object):
- #valid = 0 #0 is not checked, 1 is invalid, 2 is valid
UNTOUCHED = 0
INVALID = 100
@@ -89,37 +92,37 @@ class MetaStep(object):
def __ne__(self, other):
return self.id.int != other.id.int
+
class WorkflowFactory():
- #def __init__(self, *args, **kwargs):
booking_steps = [
- Booking_Resource_Select,
- SWConfig_Select,
- Booking_Meta
- ]
+ Booking_Resource_Select,
+ SWConfig_Select,
+ Booking_Meta
+ ]
resource_steps = [
- Define_Hardware,
- Define_Nets,
- Resource_Meta_Info,
- ]
+ Define_Hardware,
+ Define_Nets,
+ Resource_Meta_Info,
+ ]
config_steps = [
- SWConf_Resource_Select,
- Define_Software,
- Config_Software,
- ]
+ SWConf_Resource_Select,
+ Define_Software,
+ Config_Software,
+ ]
snapshot_steps = [
- Select_Host_Step,
- Image_Meta_Step
- ]
+ Select_Host_Step,
+ Image_Meta_Step
+ ]
def conjure(self, workflow_type=None, repo=None):
workflow_types = [
- self.booking_steps,
- self.resource_steps,
- self.config_steps,
- self.snapshot_steps,
+ self.booking_steps,
+ self.resource_steps,
+ self.config_steps,
+ self.snapshot_steps,
]
steps = self.make_steps(workflow_types[workflow_type], repository=repo)
diff --git a/dashboard/src/workflow/workflow_manager.py b/dashboard/src/workflow/workflow_manager.py
index 16fa468..95fefbf 100644
--- a/dashboard/src/workflow/workflow_manager.py
+++ b/dashboard/src/workflow/workflow_manager.py
@@ -8,23 +8,24 @@
##############################################################################
-from django.db import models
-from django.contrib.auth.models import User
-from django.core import serializers
-from django.http import HttpResponse, JsonResponse
+from django.http import JsonResponse
-import json
-import uuid
import random
-from resource_inventory.models import *
from booking.models import Booking
from workflow.workflow_factory import WorkflowFactory, MetaStep, MetaRelation
from workflow.models import Repository, Confirmation_Step
+from resource_inventory.models import (
+ GenericResourceBundle,
+ ConfigBundle,
+ HostConfiguration,
+ OPNFVConfig
+)
import logging
logger = logging.getLogger(__name__)
+
class SessionManager():
def __init__(self, request=None):
@@ -38,7 +39,7 @@ class SessionManager():
metaconfirm = MetaStep()
metaconfirm.index = 0
metaconfirm.short_title = "confirm"
- self.repository.el['steps'] = 1;
+ self.repository.el['steps'] = 1
self.metaworkflow = None
self.metaworkflows = []
self.metarelations = []
@@ -85,10 +86,8 @@ class SessionManager():
self.metarelations.append(relation)
self.initialized = True
-
def status(self, request):
try:
- workflows = []
steps = []
for step in self.step_meta:
steps.append(step.to_json())
@@ -109,11 +108,11 @@ class SessionManager():
responsejson['parents'] = parents
responsejson['children'] = children
return JsonResponse(responsejson, safe=False)
- except Exception as e:
+ except Exception:
pass
def render(self, request, **kwargs):
- #filter out when a step needs to handle post/form data
+ # filter out when a step needs to handle post/form data
# if 'workflow' in post data, this post request was meant for me, not step
if request.method == 'POST' and request.POST.get('workflow', None) is None:
return self.steps[self.active_index].post_render(request)
@@ -125,7 +124,7 @@ class SessionManager():
def goto(self, num, **kwargs):
self.repository.el['active_step'] = int(num)
self.active_index = int(num)
- #TODO: change to include some checking
+ # TODO: change to include some checking
def prefill_repo(self, target_id, workflow_type):
self.repository.el[self.repository.EDIT] = True
@@ -140,7 +139,6 @@ class SessionManager():
edit_object = ConfigBundle.objects.get(pk=target_id)
self.prefill_config(edit_object)
-
def prefill_booking(self, booking):
models = self.make_booking_models(booking)
confirmation = self.make_booking_confirm(booking)