blob: de7e46d2cb18153503d2a5bd4c080956484a86f0 [file] [log] [blame]
Scott Bakercae42412015-08-05 18:23:40 -07001# note: this module named xossite.py instead of site.py due to conflict with
2# /usr/lib/python2.7/site.py
3
4import os
5import pdb
6import sys
7import tempfile
8sys.path.append("/opt/tosca")
9from translator.toscalib.tosca_template import ToscaTemplate
10
Scott Bakerdebb6b12015-09-23 21:48:35 -070011from core.models import User,Deployment,Image,ImageDeployments,Flavor
Scott Bakercae42412015-08-05 18:23:40 -070012
13from xosresource import XOSResource
14
15class XOSDeployment(XOSResource):
16 provides = "tosca.nodes.Deployment"
17 xos_model = Deployment
Scott Bakerab498962015-09-22 17:26:31 -070018 copyin_props = ["accessControl"]
Scott Bakercae42412015-08-05 18:23:40 -070019
20 def get_xos_args(self):
Scott Bakerab498962015-09-22 17:26:31 -070021 args = super(XOSDeployment, self).get_xos_args()
Scott Bakercae42412015-08-05 18:23:40 -070022
23 return args
24
Scott Bakerdebb6b12015-09-23 21:48:35 -070025 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 Bakercae42412015-08-05 18:23:40 -070033
Scott Bakerdebb6b12015-09-23 21:48:35 -070034 # 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 Bakercae42412015-08-05 18:23:40 -070037
Scott Bakerdebb6b12015-09-23 21:48:35 -070038 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 Bakercae42412015-08-05 18:23:40 -070049
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