blob: 9ec5d119c6bab4f87ab165f3607b5f8cdff1e0d8 [file] [log] [blame]
Gabe Black90623222017-01-18 19:52:28 +00001from core.models import CoarseTenant
2from services.passivetest.models import PassiveTestService
3
4from xosresource import XOSResource
5
6class XOSPassiveTestService(XOSResource):
7 provides = "tosca.nodes.PassiveTest"
8 xos_model = PassiveTestService
9 copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber", "tap_ports", "reset_viv"]
10
11 def postprocess(self, obj):
12 for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"):
13 provider_service = self.get_xos_object(PassiveTestService, name=provider_service_name)
14
15 existing_tenancy = CoarseTenant.get_tenant_objects().filter(provider_service = provider_service, subscriber_service = obj)
16 if existing_tenancy:
17 self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service)))
18 else:
19 tenancy = CoarseTenant(provider_service = provider_service,
20 subscriber_service = obj)
21 tenancy.save()
22
23 self.info("Created Tenancy relationship from %s to %s" % (str(obj), str(provider_service)))
24
25 def can_delete(self, obj):
26 if obj.slices.exists():
27 self.info("Service %s has passive slices; skipping delete" % obj.name)
28 return False
29 return super(XOSPassiveTestService, self).can_delete(obj)
30