blob: 02c90375d00e30e7bfaafe004198119004adac2c [file] [log] [blame]
JianHaoce45e042017-01-16 11:06:29 +00001from services.vsgw.models import VSGWService
Murat Parlakisik66fde4d2016-09-22 13:28:13 -07002from xosresource import XOSResource
JianHaoce45e042017-01-16 11:06:29 +00003from service import XOSService
Murat Parlakisik66fde4d2016-09-22 13:28:13 -07004
5class XOSVSGWService(XOSResource):
6 provides = "tosca.nodes.VSGWService"
7 xos_model = VSGWService
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(VSGWService, 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(XOSVSGWService, self).can_delete(obj)
29