aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/snapshot_workflow.py
diff options
context:
space:
mode:
authorJustin Choquette <jchoquette@iol.unh.edu>2023-06-08 12:46:53 -0400
committerJustin Choquette <jchoquette@iol.unh.edu>2023-07-21 13:17:51 -0400
commita09db9f287a02873c0226759f8ea444bb304cd59 (patch)
tree59e744e4b998973a808abbae2d21fbdd6201d829 /src/workflow/snapshot_workflow.py
parent8ddc7e820e120f1dde4e901d3cb6f1dd3f281e65 (diff)
LaaS 3.0 Almost MVP
Change-Id: Ided9a43cf3088bb58a233dc459711c03f43e11b8 Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/workflow/snapshot_workflow.py')
-rw-r--r--src/workflow/snapshot_workflow.py116
1 files changed, 0 insertions, 116 deletions
diff --git a/src/workflow/snapshot_workflow.py b/src/workflow/snapshot_workflow.py
deleted file mode 100644
index c0e2052..0000000
--- a/src/workflow/snapshot_workflow.py
+++ /dev/null
@@ -1,116 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, 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.utils import timezone
-import json
-
-from booking.models import Booking
-from resource_inventory.models import ResourceQuery, Image
-from workflow.models import WorkflowStep
-from workflow.forms import BasicMetaForm, SnapshotHostSelectForm
-
-
-class Select_Host_Step(WorkflowStep):
- template = "snapshot_workflow/steps/select_host.html"
- title = "Select Host"
- description = "Choose which machine you want to snapshot"
- short_title = "host"
-
- def get_context(self):
- context = super(Select_Host_Step, self).get_context()
- context['form'] = SnapshotHostSelectForm()
- booking_hosts = {}
- now = timezone.now()
- user = self.repo_get(self.repo.SESSION_USER)
- bookings = Booking.objects.filter(start__lt=now, end__gt=now, owner=user)
- for booking in bookings:
- booking_hosts[booking.id] = {}
- booking_hosts[booking.id]['purpose'] = booking.purpose
- booking_hosts[booking.id]['start'] = booking.start.strftime("%Y-%m-%d")
- booking_hosts[booking.id]['end'] = booking.end.strftime("%Y-%m-%d")
- booking_hosts[booking.id]['hosts'] = []
- for genericHost in booking.resource.template.getResources():
- 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")
- if chosen_host:
- chosen = {}
- chosen['booking_id'] = self.repo_get(self.repo.SNAPSHOT_BOOKING_ID)
- chosen['hostname'] = chosen_host.template.resource.name
- context['chosen'] = chosen
- return context
-
- def post(self, post_data, user):
- host_data = post_data.get("host")
- if not host_data:
- self.set_invalid("Please select a host")
- return
- host = json.loads(host_data)
- if 'name' not in host or 'booking' not in host:
- self.set_invalid("Invalid host selected")
- return
- name = host['name']
- booking_id = host['booking']
- booking = Booking.objects.get(pk=booking_id)
- host = ResourceQuery.get(bundle=booking.resource, template__resource__name=name)
- models = self.repo_get(self.repo.SNAPSHOT_MODELS, {})
- if "host" not in models:
- models['host'] = host
- if 'snapshot' not in models:
- models['snapshot'] = Image()
- self.repo_put(self.repo.SNAPSHOT_MODELS, models)
- self.repo_put(self.repo.SNAPSHOT_BOOKING_ID, booking_id)
-
- confirm = self.repo_get(self.repo.CONFIRMATION, {})
- snap_confirm = confirm.get("snapshot", {})
- snap_confirm['host'] = name
- confirm['snapshot'] = snap_confirm
- self.repo_put(self.repo.CONFIRMATION, confirm)
- self.set_valid("Success")
-
-
-class Image_Meta_Step(WorkflowStep):
- template = "snapshot_workflow/steps/meta.html"
- title = "Additional Information"
- description = "We need some more info"
- short_title = "info"
-
- def get_context(self):
- context = super(Image_Meta_Step, self).get_context()
- name = self.repo_get(self.repo.SNAPSHOT_NAME, False)
- desc = self.repo_get(self.repo.SNAPSHOT_DESC, False)
- form = None
- if name and desc:
- form = BasicMetaForm(initial={"name": name, "description": desc})
- else:
- form = BasicMetaForm()
- context['form'] = form
- return context
-
- def post(self, post_data, user):
- form = BasicMetaForm(post_data)
- if form.is_valid():
- name = form.cleaned_data['name']
- self.repo_put(self.repo.SNAPSHOT_NAME, name)
- description = form.cleaned_data['description']
- self.repo_put(self.repo.SNAPSHOT_DESC, description)
-
- confirm = self.repo_get(self.repo.CONFIRMATION, {})
- snap_confirm = confirm.get("snapshot", {})
- snap_confirm['name'] = name
- snap_confirm['description'] = description
- confirm['snapshot'] = snap_confirm
- self.repo_put(self.repo.CONFIRMATION, confirm)
-
- self.set_valid("Success")
- else:
- self.set_invalid("Please Fill out the Form")