blob: 7e63ba0b50bee9eb807f87a3cfc26a7b78750a36 [file] [log] [blame]
Scott Baker9fce62e2015-08-03 15:43:54 -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 Slice,User,Site
9
10from xosresource import XOSResource
11
12class XOSSlice(XOSResource):
13 provides = "tosca.nodes.Slice"
Scott Baker9fdb39f2015-08-04 16:44:18 -070014 xos_model = Slice
Scott Baker9fce62e2015-08-03 15:43:54 -070015
Scott Baker9fdb39f2015-08-04 16:44:18 -070016 def get_xos_args(self):
17 site_name = self.get_requirement("tosca.relationships.MemberOfSite", throw_exception=True)
18 site = self.get_xos_object(Site, login_base=site_name)
19 return {"name": self.nodetemplate.name,
20 "site": site}
21
22 def create(self):
Scott Baker9fce62e2015-08-03 15:43:54 -070023 nodetemplate = self.nodetemplate
24 sliceName = nodetemplate.name
25
Scott Baker9fdb39f2015-08-04 16:44:18 -070026 xos_args = self.get_xos_args()
27 slice = Slice(**xos_args)
28 slice.caller = self.user
29 slice.save()
Scott Baker9fce62e2015-08-03 15:43:54 -070030
Scott Baker9fdb39f2015-08-04 16:44:18 -070031 self.info("Created Slice '%s' on Site '%s'" % (str(slice), str(slice.site)))
Scott Baker9fce62e2015-08-03 15:43:54 -070032
Scott Baker9fce62e2015-08-03 15:43:54 -070033