aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/workflow/models.py')
-rw-r--r--src/workflow/models.py109
1 files changed, 33 insertions, 76 deletions
diff --git a/src/workflow/models.py b/src/workflow/models.py
index df00d21..173fdba 100644
--- a/src/workflow/models.py
+++ b/src/workflow/models.py
@@ -18,7 +18,7 @@ import requests
from workflow.forms import ConfirmationForm
from api.models import JobFactory
from dashboard.exceptions import ResourceAvailabilityException, ModelValidationException
-from resource_inventory.models import Image, InterfaceConfiguration, OPNFVConfig, ResourceOPNFVConfig, NetworkRole
+from resource_inventory.models import Image, OPNFVConfig, ResourceOPNFVConfig, NetworkRole
from resource_inventory.resource_manager import ResourceManager
from resource_inventory.pdf_templater import PDFTemplater
from notifier.manager import NotificationHandler
@@ -352,6 +352,7 @@ class Confirmation_Step(WorkflowStep):
self.set_valid("Confirmed")
elif data == "False":
+ self.repo.cancel()
self.set_valid("Canceled")
else:
self.set_invalid("Bad Form Contents")
@@ -366,14 +367,14 @@ class Repository():
MODELS = "models"
RESOURCE_SELECT = "resource_select"
CONFIRMATION = "confirmation"
- SELECTED_GRESOURCE_BUNDLE = "selected generic bundle pk"
+ SELECTED_RESOURCE_TEMPLATE = "selected resource template pk"
SELECTED_CONFIG_BUNDLE = "selected config bundle pk"
SELECTED_OPNFV_CONFIG = "selected opnfv deployment config"
- GRESOURCE_BUNDLE_MODELS = "generic_resource_bundle_models"
- GRESOURCE_BUNDLE_INFO = "generic_resource_bundle_info"
+ RESOURCE_TEMPLATE_MODELS = "generic_resource_template_models"
+ RESOURCE_TEMPLATE_INFO = "generic_resource_template_info"
BOOKING = "booking"
LAB = "lab"
- GRB_LAST_HOSTLIST = "grb_network_previous_hostlist"
+ RCONFIG_LAST_HOSTLIST = "resource_configuration_network_previous_hostlist"
BOOKING_FORMS = "booking_forms"
SWCONF_HOSTS = "swconf_hosts"
BOOKING_MODELS = "booking models"
@@ -391,6 +392,9 @@ class Repository():
SNAPSHOT_DESC = "description of the snapshot"
BOOKING_INFO_FILE = "the INFO.yaml file for this user's booking"
+ # new keys for migration to using ResourceTemplates:
+ RESOURCE_TEMPLATE_MODELS = "current working model of resource template"
+
# migratory elements of segmented workflow
# each of these is the end result of a different workflow.
HAS_RESULT = "whether or not workflow has a result"
@@ -399,7 +403,7 @@ class Repository():
def get_child_defaults(self):
return_tuples = []
- for key in [self.SELECTED_GRESOURCE_BUNDLE, self.SESSION_USER]:
+ for key in [self.SELECTED_RESOURCE_TEMPLATE, self.SESSION_USER]:
return_tuples.append((key, self.el.get(key)))
return return_tuples
@@ -428,6 +432,14 @@ class Repository():
else:
history[key].append(id)
+ def cancel(self):
+ if self.RESOURCE_TEMPLATE_MODELS in self.el:
+ models = self.el[self.RESOURCE_TEMPLATE_MODELS]
+ if models['template'].temporary:
+ models['template'].delete()
+ # deleting current template should cascade delete all
+ # necessary related models
+
def make_models(self):
if self.SNAPSHOT_MODELS in self.el:
errors = self.make_snapshot()
@@ -435,13 +447,13 @@ class Repository():
return errors
# if GRB WF, create it
- if self.GRESOURCE_BUNDLE_MODELS in self.el:
+ if self.RESOURCE_TEMPLATE_MODELS in self.el:
errors = self.make_generic_resource_bundle()
if errors:
return errors
else:
self.el[self.HAS_RESULT] = True
- self.el[self.RESULT_KEY] = self.SELECTED_GRESOURCE_BUNDLE
+ self.el[self.RESULT_KEY] = self.SELECTED_RESOURCE_TEMPLATE
return
if self.CONFIG_MODELS in self.el:
@@ -507,78 +519,23 @@ class Repository():
def make_generic_resource_bundle(self):
owner = self.el[self.SESSION_USER]
- if self.GRESOURCE_BUNDLE_MODELS in self.el:
- models = self.el[self.GRESOURCE_BUNDLE_MODELS]
- if 'hosts' in models:
- hosts = models['hosts']
- else:
- return "GRB has no hosts. CODE:0x0002"
- if 'bundle' in models:
- bundle = models['bundle']
- else:
- return "GRB, no bundle in models. CODE:0x0003"
-
- try:
- bundle.owner = owner
- bundle.save()
- except Exception as e:
- return "GRB, saving bundle generated exception: " + str(e) + " CODE:0x0004"
- try:
- for host in hosts:
- genericresource = host.resource
- genericresource.bundle = bundle
- genericresource.save()
- host.resource = genericresource
- host.save()
- except Exception as e:
- return "GRB, saving hosts generated exception: " + str(e) + " CODE:0x0005"
-
- if 'networks' in models:
- for net in models['networks'].values():
- net.bundle = bundle
- net.save()
-
- if 'interfaces' in models:
- for interface_set in models['interfaces'].values():
- for interface in interface_set:
- try:
- interface.host = interface.host
- interface.save()
- except Exception:
- return "GRB, saving interface " + str(interface) + " failed. CODE:0x0019"
- else:
- return "GRB, no interface set provided. CODE:0x001a"
-
- if 'connections' in models:
- for resource_name, mapping in models['connections'].items():
- for profile_name, connection_set in mapping.items():
- interface = InterfaceConfiguration.objects.get(
- profile__name=profile_name,
- host__resource__name=resource_name,
- host__resource__bundle=models['bundle']
- )
- for connection in connection_set:
- try:
- connection.network = connection.network
- connection.save()
- interface.connections.add(connection)
- except Exception as e:
- return "GRB, saving vlan " + str(connection) + " failed. Exception: " + str(e) + ". CODE:0x0017"
- else:
- return "GRB, no vlan set provided. CODE:0x0018"
+ if self.RESOURCE_TEMPLATE_MODELS in self.el:
+ models = self.el[self.RESOURCE_TEMPLATE_MODELS]
+ models['template'].owner = owner
+ models['template'].temporary = False
+ models['template'].save()
+ self.el[self.RESULT] = models['template']
+ self.el[self.HAS_RESULT] = True
+ return False
else:
return "GRB no models given. CODE:0x0001"
- self.el[self.RESULT] = bundle
- self.el[self.HAS_RESULT] = True
- return False
-
def make_software_config_bundle(self):
models = self.el[self.CONFIG_MODELS]
if 'bundle' in models:
bundle = models['bundle']
- bundle.bundle = self.el[self.SELECTED_GRESOURCE_BUNDLE]
+ bundle.bundle = self.el[self.SELECTED_RESOURCE_TEMPLATE]
try:
bundle.save()
except Exception as e:
@@ -589,8 +546,8 @@ class Repository():
if 'host_configs' in models:
host_configs = models['host_configs']
for host_config in host_configs:
- host_config.bundle = host_config.bundle
- host_config.host = host_config.host
+ host_config.template = host_config.template
+ host_config.profile = host_config.profile
try:
host_config.save()
except Exception as e:
@@ -623,8 +580,8 @@ class Repository():
selected_grb = None
- if self.SELECTED_GRESOURCE_BUNDLE in self.el:
- selected_grb = self.el[self.SELECTED_GRESOURCE_BUNDLE]
+ if self.SELECTED_RESOURCE_TEMPLATE in self.el:
+ selected_grb = self.el[self.SELECTED_RESOURCE_TEMPLATE]
else:
return "BOOK, no selected resource. CODE:0x000e"