aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/sw_bundle_workflow.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2020-05-15 14:58:37 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2020-05-15 17:42:23 -0400
commit530271c247a4ce538e3aa69fd3893481fada44ab (patch)
tree48640138c825bf0906a1c261c28939d5311ae6d6 /src/workflow/sw_bundle_workflow.py
parent6bf37e9864787e0398a1d2e1cdd10b40a8ebc6e6 (diff)
Merge resource branch
This pulls master up to date to include changes to models and surrounding infra that allow for multi-node templates and merging of pods Squashed commit of the following: commit abc8f27d9c6b05fb3afcb9b00dc35c0f2232d1a6 Author: Sawyer Bergeron <sawyerbergeron@gmail.com> Date: Thu Apr 2 14:05:26 2020 -0400 Start fixing workflow for model changes Change-Id: I79df975ef45abf2e6e69594d358bbd205938828f Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.com> Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> commit 7a7e2182acd0ea94e19aba4926c3a12771b30a6d Author: sms1097 <ssmith@iol.unh.edu> Date: Tue Mar 31 15:13:06 2020 -0400 Working on workflow refactoring Change-Id: I4141b6aca98aff7bff9cb78a7d5594e25eb45e98 Signed-off-by: Sean Smith <ssmith@iol.unh.edu> commit c09050ae2814f07af58557b40f9ed3559063d2c7 Merge: 71438d9 b5ccdc4 Author: Parker Berberian <pberberian@iol.unh.edu> Date: Tue Mar 24 20:34:16 2020 +0000 Merge "Able to delete configurations and view lab details" into resource commit b5ccdc4ffbb883c20f2f6f69aeef5002aef5db53 Author: sms1097 <ssmith@iol.unh.edu> Date: Thu Mar 19 17:08:12 2020 -0400 Able to delete configurations and view lab details Change-Id: Ib15c86d84f4cc7e7745551889ce91c89b5de46e2 Signed-off-by: Sean Smith <ssmith@iol.unh.edu> Change-Id: Id6748c6bea67773a861921394d88579730246598 commit 71438d9a35cdb316cece865c9d410aeffb0053d8 Merge: 5460d0d a758223 Author: Parker Berberian <pberberian@iol.unh.edu> Date: Thu Mar 19 18:51:09 2020 +0000 Merge "Add / Fix tests for refactor" into resource commit 5460d0d447b075433a763f9bfa33448b88ec8393 Merge: a9063a3 f55d839 Author: Parker Berberian <pberberian@iol.unh.edu> Date: Wed Mar 18 15:59:37 2020 +0000 Merge "Fixed the quick booking form resource template filtering. Added some more models to the admin page." into resource commit f55d839a029ab1f5ab1273872e71a97fa1d5108b Author: Adam Hassick <ahassick@iol.unh.edu> Date: Tue Mar 17 11:35:40 2020 -0400 Fixed the quick booking form resource template filtering. Added some more models to the admin page. Signed-off-by: Adam Hassick <ahassick@iol.unh.edu> Change-Id: I2d2e7aeb96b10c231804a62f37a476039c954b7b commit a9063a347c4ebef0e53a17f198468bb135772810 Author: Parker Berberian <pberberian@iol.unh.edu> Date: Wed Mar 18 10:29:51 2020 -0400 Fixes Some Issues with Quick Booking Seen in the Akraino lab Signed-off-by: Parker Berberian <pberberian@iol.unh.edu> Change-Id: I2a1e843fbaa7984225f2f80742dad59dc348fbf2 commit a758223f44c6fec595b055d7c9b232b00e9174a0 Author: Parker Berberian <pberberian@iol.unh.edu> Date: Tue Mar 17 11:07:32 2020 -0400 Add / Fix tests for refactor Change-Id: I0526d1942f87707082a4eb1c8c98910f84481c23 Signed-off-by: Parker Berberian <pberberian@iol.unh.edu> Author: Parker Berberian <pberberian@iol.unh.edu> Add "Pod" Column to booking list Signed-off-by: Parker Berberian <pberberian@iol.unh.edu> Change-Id: I270913283bf1e5815cadf622ba2fd5f98bb61675 Author: Parker Berberian <pberberian@iol.unh.edu> Fixes that make the Akraino dashboard work Signed-off-by: Parker Berberian <pberberian@iol.unh.edu> Change-Id: I81746473a4511ef7d46445a7b16809a6e9da100f Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> Change-Id: I4b428e7c8a8d401d7bae95cba01077feb0332a7f Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/workflow/sw_bundle_workflow.py')
-rw-r--r--src/workflow/sw_bundle_workflow.py196
1 files changed, 0 insertions, 196 deletions
diff --git a/src/workflow/sw_bundle_workflow.py b/src/workflow/sw_bundle_workflow.py
deleted file mode 100644
index 686f46f..0000000
--- a/src/workflow/sw_bundle_workflow.py
+++ /dev/null
@@ -1,196 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 Sawyer Bergeron, Parker Berberian, and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-from django.forms import formset_factory
-
-from workflow.models import WorkflowStep
-from workflow.forms import BasicMetaForm, HostSoftwareDefinitionForm
-from workflow.booking_workflow import Abstract_Resource_Select
-from resource_inventory.models import Image, ResourceConfiguration, ResourceTemplate
-
-
-class SWConf_Resource_Select(Abstract_Resource_Select):
- workflow_type = "configuration"
-
-
-class Define_Software(WorkflowStep):
- template = 'config_bundle/steps/define_software.html'
- title = "Pick Software"
- description = "Choose the opnfv and image of your machines"
- short_title = "host config"
-
- def build_filter_data(self, hosts_data):
- """
- Build list of Images to filter out.
-
- returns a 2D array of images to exclude
- based on the ordering of the passed
- hosts_data
- """
- filter_data = []
- user = self.repo_get(self.repo.SESSION_USER)
- lab = self.repo_get(self.repo.SELECTED_GRESOURCE_BUNDLE).lab
- for i, host_data in enumerate(hosts_data):
- host = ResourceConfiguration.objects.get(pk=host_data['host_id'])
- wrong_owner = Image.objects.exclude(owner=user).exclude(public=True)
- wrong_host = Image.objects.exclude(host_type=host.profile)
- wrong_lab = Image.objects.exclude(from_lab=lab)
- excluded_images = wrong_owner | wrong_host | wrong_lab
- filter_data.append([])
- for image in excluded_images:
- filter_data[i].append(image.pk)
- return filter_data
-
- def create_hostformset(self, hostlist, data=None):
- hosts_initial = []
- host_configs = self.repo_get(self.repo.CONFIG_MODELS, {}).get("host_configs", False)
- if host_configs:
- for config in host_configs:
- hosts_initial.append({
- 'host_id': config.host.id,
- 'host_name': config.host.resource.name,
- 'headnode': config.is_head_node,
- 'image': config.image
- })
- else:
- for host in hostlist:
- hosts_initial.append({
- 'host_id': host.id,
- 'host_name': host.resource.name
- })
-
- HostFormset = formset_factory(HostSoftwareDefinitionForm, extra=0)
- filter_data = self.build_filter_data(hosts_initial)
-
- class SpecialHostFormset(HostFormset):
- def get_form_kwargs(self, index):
- kwargs = super(SpecialHostFormset, self).get_form_kwargs(index)
- if index is not None:
- kwargs['imageQS'] = Image.objects.exclude(pk__in=filter_data[index])
- return kwargs
-
- if data:
- return SpecialHostFormset(data, initial=hosts_initial)
- return SpecialHostFormset(initial=hosts_initial)
-
- def get_host_list(self, grb=None):
- if grb is None:
- grb = self.repo_get(self.repo.SELECTED_GRESOURCE_BUNDLE, False)
- if not grb:
- return []
- if grb.id:
- return ResourceConfiguration.objects.filter(resource__bundle=grb)
- generic_hosts = self.repo_get(self.repo.GRESOURCE_BUNDLE_MODELS, {}).get("hosts", [])
- return generic_hosts
-
- def get_context(self):
- context = super(Define_Software, self).get_context()
-
- grb = self.repo_get(self.repo.SELECTED_GRESOURCE_BUNDLE, False)
-
- if grb:
- context["grb"] = grb
- formset = self.create_hostformset(self.get_host_list(grb))
- context["formset"] = formset
- context['headnode'] = self.repo_get(self.repo.CONFIG_MODELS, {}).get("headnode_index", 1)
- else:
- context["error"] = "Please select a resource first"
- self.set_invalid("Step requires information that is not yet provided by previous step")
-
- return context
-
- def post(self, post_data, user):
- models = self.repo_get(self.repo.CONFIG_MODELS, {})
- if "bundle" not in models:
- models['bundle'] = ResourceTemplate(owner=self.repo_get(self.repo.SESSION_USER))
-
- confirm = self.repo_get(self.repo.CONFIRMATION, {})
-
- hosts = self.get_host_list()
- models['headnode_index'] = post_data.get("headnode", 1)
- formset = self.create_hostformset(hosts, data=post_data)
- has_headnode = False
- if formset.is_valid():
- models['host_configs'] = []
- confirm_hosts = []
- for i, form in enumerate(formset):
- host = hosts[i]
- image = form.cleaned_data['image']
- headnode = form.cleaned_data['headnode']
- if headnode:
- has_headnode = True
- bundle = models['bundle']
- hostConfig = ResourceConfiguration(
- host=host,
- image=image,
- bundle=bundle,
- is_head_node=headnode
- )
- models['host_configs'].append(hostConfig)
- confirm_hosts.append({
- "name": host.resource.name,
- "image": image.name,
- "headnode": headnode
- })
-
- if not has_headnode:
- self.set_invalid('Must have one "Headnode" per POD')
- return
-
- self.repo_put(self.repo.CONFIG_MODELS, models)
- if "configuration" not in confirm:
- confirm['configuration'] = {}
- confirm['configuration']['hosts'] = confirm_hosts
- self.repo_put(self.repo.CONFIRMATION, confirm)
- self.set_valid("Completed")
- else:
- self.set_invalid("Please complete all fields")
-
-
-class Config_Software(WorkflowStep):
- template = 'config_bundle/steps/config_software.html'
- title = "Other Info"
- description = "Give your software config a name, description, and other stuff"
- short_title = "config info"
-
- def get_context(self):
- context = super(Config_Software, self).get_context()
-
- initial = {}
- models = self.repo_get(self.repo.CONFIG_MODELS, {})
- bundle = models.get("bundle", False)
- if bundle:
- initial['name'] = bundle.name
- initial['description'] = bundle.description
- context["form"] = BasicMetaForm(initial=initial)
- return context
-
- def post(self, post_data, user):
- models = self.repo_get(self.repo.CONFIG_MODELS, {})
- if "bundle" not in models:
- models['bundle'] = ResourceTemplate(owner=self.repo_get(self.repo.SESSION_USER))
-
- confirm = self.repo_get(self.repo.CONFIRMATION, {})
- if "configuration" not in confirm:
- confirm['configuration'] = {}
-
- form = BasicMetaForm(post_data)
- if form.is_valid():
- models['bundle'].name = form.cleaned_data['name']
- models['bundle'].description = form.cleaned_data['description']
-
- confirm['configuration']['name'] = form.cleaned_data['name']
- confirm['configuration']['description'] = form.cleaned_data['description']
- self.set_valid("Complete")
- else:
- self.set_invalid("Please correct the errors shown below")
-
- self.repo_put(self.repo.CONFIG_MODELS, models)
- self.repo_put(self.repo.CONFIRMATION, confirm)