Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame^] | 1 | import os |
| 2 | import pdb |
| 3 | import sys |
| 4 | import tempfile |
| 5 | sys.path.append("/opt/tosca") |
| 6 | from translator.toscalib.tosca_template import ToscaTemplate |
| 7 | import pdb |
| 8 | |
| 9 | from core.models import Service,User,CoarseTenant |
| 10 | from services.exampleservice.models import ExampleService |
| 11 | |
| 12 | from xosresource import XOSResource |
| 13 | |
| 14 | class XOSExampleService(XOSResource): |
| 15 | provides = "tosca.nodes.ExampleService" |
| 16 | xos_model = ExampleService |
| 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(ExampleService, 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(XOSExampleService, self).can_delete(obj) |
| 38 | |