blob: 5d2e72107c714da92a8d1173eb704491f2d6616d [file] [log] [blame]
Scott Baker619de672016-06-20 12:49:38 -07001from xosresource import XOSResource
Zack Williams1ce6c382016-10-05 18:02:09 -07002from core.models import Service, User, CoarseTenant
3from services.exampleservice.models import ExampleService
Scott Baker619de672016-06-20 12:49:38 -07004
5class XOSExampleService(XOSResource):
6 provides = "tosca.nodes.ExampleService"
7 xos_model = ExampleService
8 copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber", "service_message"]
9
10 def postprocess(self, obj):
11 for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"):
12 provider_service = self.get_xos_object(ExampleService, name=provider_service_name)
13
14 existing_tenancy = CoarseTenant.get_tenant_objects().filter(provider_service = provider_service, subscriber_service = obj)
15 if existing_tenancy:
16 self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service)))
17 else:
18 tenancy = CoarseTenant(provider_service = provider_service,
19 subscriber_service = obj)
20 tenancy.save()
21
22 self.info("Created Tenancy relationship from %s to %s" % (str(obj), str(provider_service)))
23
24 def can_delete(self, obj):
25 if obj.slices.exists():
26 self.info("Service %s has active slices; skipping delete" % obj.name)
27 return False
28 return super(XOSExampleService, self).can_delete(obj)
29