Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 1 | from xosresource import XOSResource |
Zack Williams | 1ce6c38 | 2016-10-05 18:02:09 -0700 | [diff] [blame] | 2 | from core.models import Service, User, CoarseTenant |
| 3 | from services.exampleservice.models import ExampleService |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 4 | |
| 5 | class 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 | |