1 ##############################################################################
2 # Copyright (c) 2018 Sawyer Bergeron, Parker Berberian, and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from workflow.booking_workflow import Booking_Resource_Select, SWConfig_Select, Booking_Meta
12 from workflow.resource_bundle_workflow import Define_Hardware, Define_Nets, Resource_Meta_Info
13 from workflow.sw_bundle_workflow import Config_Software, Define_Software, SWConf_Resource_Select
14 from workflow.snapshot_workflow import Select_Host_Step, Image_Meta_Step
15 from workflow.models import Repository, Confirmation_Step
20 logger = logging.getLogger(__name__)
23 class BookingMetaWorkflow(object):
29 class ResourceMetaWorkflow(object):
34 class ConfigMetaWorkflow(object):
38 class MetaStep(object):
44 def set_invalid(self, message, code=100):
46 self.message = message
48 def set_valid(self, message, code=200):
50 self.message = message
52 def __init__(self, *args, **kwargs):
53 self.short_title = "error"
57 self.id = uuid.uuid4()
61 'title': self.short_title,
62 'skip': self.skip_step,
64 'message': self.message,
68 return "metastep: " + str(self.short_title)
73 def __eq__(self, other):
74 return self.id.int == other.id.int
76 def __ne__(self, other):
77 return self.id.int != other.id.int
79 class Workflow(object):
80 def __init__(self, steps, metasteps, repository):
81 self.repository = repository
83 self.metasteps = metasteps
86 class WorkflowFactory():
88 Booking_Resource_Select,
100 SWConf_Resource_Select,
110 def conjure(self, workflow_type=None, repo=None):
118 steps = self.make_steps(workflow_types[workflow_type], repository=repo)
119 meta_steps = self.metaize(steps=steps, wf_type=workflow_type)
120 return steps, meta_steps
122 def create_workflow(self, workflow_type=None, repo=None):
123 steps, meta_steps = self.conjure(workflow_type, repo)
124 c_step = self.make_step(Confirmation_Step, repo)
125 metaconfirm = MetaStep()
126 metaconfirm.short_title = "confirm"
127 metaconfirm.index = len(steps)
129 meta_steps.append(metaconfirm)
130 return Workflow(steps, meta_steps, repo)
132 def make_steps(self, step_types, repository):
134 for step_type in step_types:
135 steps.append(self.make_step(step_type, repository))
139 def make_step(self, step_type, repository):
140 iden = step_type.description + step_type.title + step_type.template
141 return step_type(iden, repository)
143 def metaize(self, steps, wf_type):
146 meta_step = MetaStep()
147 meta_step.short_title = step.short_title
148 meta_dict.append(meta_step)
149 step.metastep = meta_step