Scott Baker | 9fce62e | 2015-08-03 15:43:54 -0700 | [diff] [blame] | 1 | import os |
| 2 | import pdb |
| 3 | import sys |
| 4 | import tempfile |
| 5 | sys.path.append("/opt/tosca") |
| 6 | from translator.toscalib.tosca_template import ToscaTemplate |
| 7 | |
| 8 | from core.models import Slice,User,Site |
| 9 | |
| 10 | from xosresource import XOSResource |
| 11 | |
| 12 | class XOSSlice(XOSResource): |
| 13 | provides = "tosca.nodes.Slice" |
Scott Baker | 9fdb39f | 2015-08-04 16:44:18 -0700 | [diff] [blame] | 14 | xos_model = Slice |
Scott Baker | 9fce62e | 2015-08-03 15:43:54 -0700 | [diff] [blame] | 15 | |
Scott Baker | 9fdb39f | 2015-08-04 16:44:18 -0700 | [diff] [blame] | 16 | 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 Baker | 9fce62e | 2015-08-03 15:43:54 -0700 | [diff] [blame] | 23 | nodetemplate = self.nodetemplate |
| 24 | sliceName = nodetemplate.name |
| 25 | |
Scott Baker | 9fdb39f | 2015-08-04 16:44:18 -0700 | [diff] [blame] | 26 | xos_args = self.get_xos_args() |
| 27 | slice = Slice(**xos_args) |
| 28 | slice.caller = self.user |
| 29 | slice.save() |
Scott Baker | 9fce62e | 2015-08-03 15:43:54 -0700 | [diff] [blame] | 30 | |
Scott Baker | 9fdb39f | 2015-08-04 16:44:18 -0700 | [diff] [blame] | 31 | self.info("Created Slice '%s' on Site '%s'" % (str(slice), str(slice.site))) |
Scott Baker | 9fce62e | 2015-08-03 15:43:54 -0700 | [diff] [blame] | 32 | |
Scott Baker | 9fce62e | 2015-08-03 15:43:54 -0700 | [diff] [blame] | 33 | |