Scott Baker | cae4241 | 2015-08-05 18:23:40 -0700 | [diff] [blame] | 1 | # note: this module named xossite.py instead of site.py due to conflict with |
| 2 | # /usr/lib/python2.7/site.py |
| 3 | |
| 4 | import os |
| 5 | import pdb |
| 6 | import sys |
| 7 | import tempfile |
| 8 | sys.path.append("/opt/tosca") |
| 9 | from translator.toscalib.tosca_template import ToscaTemplate |
| 10 | |
Scott Baker | debb6b1 | 2015-09-23 21:48:35 -0700 | [diff] [blame] | 11 | from core.models import User,Deployment,Image,ImageDeployments,Flavor |
Scott Baker | cae4241 | 2015-08-05 18:23:40 -0700 | [diff] [blame] | 12 | |
| 13 | from xosresource import XOSResource |
| 14 | |
| 15 | class XOSDeployment(XOSResource): |
| 16 | provides = "tosca.nodes.Deployment" |
| 17 | xos_model = Deployment |
Scott Baker | ab49896 | 2015-09-22 17:26:31 -0700 | [diff] [blame] | 18 | copyin_props = ["accessControl"] |
Scott Baker | cae4241 | 2015-08-05 18:23:40 -0700 | [diff] [blame] | 19 | |
| 20 | def get_xos_args(self): |
Scott Baker | ab49896 | 2015-09-22 17:26:31 -0700 | [diff] [blame] | 21 | args = super(XOSDeployment, self).get_xos_args() |
Scott Baker | cae4241 | 2015-08-05 18:23:40 -0700 | [diff] [blame] | 22 | |
| 23 | return args |
| 24 | |
Scott Baker | debb6b1 | 2015-09-23 21:48:35 -0700 | [diff] [blame] | 25 | def postprocess(self, obj): |
| 26 | for imageName in self.get_requirements("tosca.relationships.SupportsImage"): |
| 27 | image = self.get_xos_object(Image, name=imageName) |
| 28 | imageDeps = ImageDeployments.objects.filter(deployment=obj, image=image) |
| 29 | if not imageDeps: |
| 30 | self.info("Attached Image %s to Deployment %s" % (image, obj)) |
| 31 | imageDep = ImageDeployments(deployment=obj, image=image) |
| 32 | imageDep.save() |
Scott Baker | cae4241 | 2015-08-05 18:23:40 -0700 | [diff] [blame] | 33 | |
Scott Baker | debb6b1 | 2015-09-23 21:48:35 -0700 | [diff] [blame] | 34 | # Be a little more lightweight with 'flavors'. Since we install flavors |
| 35 | # as a fixture rather than using TOSCA, we can just let the user |
| 36 | # use a comma-separated list. |
Scott Baker | cae4241 | 2015-08-05 18:23:40 -0700 | [diff] [blame] | 37 | |
Scott Baker | debb6b1 | 2015-09-23 21:48:35 -0700 | [diff] [blame] | 38 | flavors = self.get_property("flavors") |
| 39 | if flavors: |
| 40 | flavors = flavors.split(",") |
| 41 | flavors = [x.strip() for x in flavors] |
| 42 | |
| 43 | for flavor in flavors: |
| 44 | flavor = self.get_xos_object(Flavor, name=flavor) |
| 45 | if not flavor.deployments.filter(id=obj.id).exists(): |
| 46 | self.info("Attached flavor %s to deployment %s" % (flavor, obj)) |
| 47 | flavor.deployments.add(obj) |
| 48 | flavor.save() |
Scott Baker | cae4241 | 2015-08-05 18:23:40 -0700 | [diff] [blame] | 49 | |
| 50 | def delete(self, obj): |
| 51 | if obj.sites.exists(): |
| 52 | self.info("Deployment %s has active sites; skipping delete" % obj.name) |
| 53 | return |
| 54 | #if obj.nodes.exists(): |
| 55 | # self.info("Deployment %s has active nodes; skipping delete" % obj.name) |
| 56 | # return |
| 57 | super(XOSDeployment, self).delete(obj) |
| 58 | |
| 59 | |
| 60 | |