blob: f26b8b77d91a0a34a7658fd9f6f51c19e493e5a2 [file] [log] [blame]
Scott Baker619de672016-06-20 12:49:38 -07001import os
2import pdb
3import sys
4import tempfile
5sys.path.append("/opt/tosca")
6from translator.toscalib.tosca_template import ToscaTemplate
7import pdb
8
9from core.models import Service,User,CoarseTenant
10from services.exampleservice.models import ExampleService
11
12from xosresource import XOSResource
13
14class XOSExampleService(XOSResource):
15 provides = "tosca.nodes.ExampleService"
16 xos_model = ExampleService
17 copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber", "service_message"]
18
19 def postprocess(self, obj):
20 for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"):
21 provider_service = self.get_xos_object(ExampleService, name=provider_service_name)
22
23 existing_tenancy = CoarseTenant.get_tenant_objects().filter(provider_service = provider_service, subscriber_service = obj)
24 if existing_tenancy:
25 self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service)))
26 else:
27 tenancy = CoarseTenant(provider_service = provider_service,
28 subscriber_service = obj)
29 tenancy.save()
30
31 self.info("Created Tenancy relationship from %s to %s" % (str(obj), str(provider_service)))
32
33 def can_delete(self, obj):
34 if obj.slices.exists():
35 self.info("Service %s has active slices; skipping delete" % obj.name)
36 return False
37 return super(XOSExampleService, self).can_delete(obj)
38