blob: 6289ffd1c4eb77e9d36a7abeb8d9bb2ee3206b2d [file] [log] [blame]
Murat Parlakisik66fde4d2016-09-22 13:28:13 -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.vsgwservice.models import VSGWService
11
12from xosresource import XOSResource
13
14class XOSVSGWService(XOSResource):
15 provides = "tosca.nodes.VSGWService"
16 xos_model = VSGWService
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(VSGWService, 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(XOSVSGWService, self).can_delete(obj)
38