blob: ed6734c844a4ed224f73efc99f3f69978a20ab3d [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 Baker07c71fc2015-09-24 15:37:16 -070011from core.models import User,Deployment,DeploymentRole,DeploymentPrivilege,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
Scott Baker07c71fc2015-09-24 15:37:16 -070050 rolemap = ( ("tosca.relationships.AdminPrivilege", "admin"), )
51 self.postprocess_privileges(DeploymentRole, DeploymentPrivilege, rolemap, obj, "deployment")
52
Scott Bakercae42412015-08-05 18:23:40 -070053 def delete(self, obj):
Scott Bakercae42412015-08-05 18:23:40 -070054 if obj.sites.exists():
55 self.info("Deployment %s has active sites; skipping delete" % obj.name)
56 return
Scott Bakerf2d2ef02015-10-08 16:51:08 -070057 for sd in obj.sitedeployments.all():
58 if sd.nodes.exists():
59 self.info("Deployment %s has active nodes; skipping delete" % obj.name)
60 return
Scott Bakercae42412015-08-05 18:23:40 -070061 #if obj.nodes.exists():
62 # self.info("Deployment %s has active nodes; skipping delete" % obj.name)
63 # return
64 super(XOSDeployment, self).delete(obj)
65
66
67