JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame] | 1 | from services.vsgw.models import VSGWService |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 2 | from xosresource import XOSResource |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame] | 3 | from service import XOSService |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 4 | |
| 5 | class 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 | |