blob: 59b915b6d0d9173e6fbcf60554b331e53fb49127 [file] [log] [blame]
Scott Baker0f058742015-09-16 16:14:42 -07001import os
2import pdb
3import sys
4import tempfile
5sys.path.append("/opt/tosca")
6from translator.toscalib.tosca_template import ToscaTemplate
7
8from core.models import Node, Site, Deployment, SiteDeployment
9
10from xosresource import XOSResource
11
12class XOSNode(XOSResource):
13 provides = "tosca.nodes.Node"
14 xos_model = Node
15
16 def get_xos_args(self):
17 args = {"name": self.nodetemplate.name}
18
19 site = None
20 siteName = self.get_requirement("tosca.relationships.MemberOfSite", throw_exception=False)
21 if siteName:
Scott Bakerbff14a42015-09-30 21:00:31 -070022 site = self.get_xos_object(Site, login_base=siteName)
Scott Baker0f058742015-09-16 16:14:42 -070023 args["site"] = site
24
25 deploymentName = self.get_requirement("tosca.relationships.MemberOfDeployment", throw_exception=False)
26 if deploymentName:
27 deployment = self.get_xos_object(Deployment, name=deploymentName)
28
29 if site:
30 siteDeployment = self.get_xos_object(SiteDeployment, site=site, deployment=deployment, throw_exception=True)
31 args["site_deployment"] = siteDeployment
32
33 return args
34
35 def create(self):
36 nodetemplate = self.nodetemplate
37 sliceName = nodetemplate.name
38
39 xos_args = self.get_xos_args()
40
41 if not xos_args.get("site", None):
42 raise Exception("Site is a required field of Node")
43 if not xos_args.get("site_deployment", None):
44 raise Exception("Deployment is a required field of Node")
45
46 node = Node(**xos_args)
47 node.caller = self.user
48 node.save()
49
50 self.postprocess(node)
51
52 self.info("Created Node '%s' on Site '%s' Deployment '%s'" % (str(node), str(node.site), str(node.site_deployment.deployment)))
53
54 def delete(self, obj):
55 super(XOSNode, self).delete(obj)
56
57
58