Gabe Black | 4c040b7 | 2016-11-17 22:35:04 +0000 | [diff] [blame] | 1 | from core.models import Service,User,CoarseTenant |
| 2 | from services.activetest.models import ActiveTestService, Qt600Service, VpmaService, VtaService |
| 3 | |
| 4 | from xosresource import XOSResource |
| 5 | |
| 6 | class XOSActiveTestService(XOSResource): |
| 7 | provides = "tosca.nodes.ActiveTest" |
| 8 | xos_model = ActiveTestService |
| 9 | copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber"] |
| 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(ActiveTestService, 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 active slices; skipping delete" % obj.name) |
| 28 | return False |
| 29 | return super(XOSActiveTestService, self).can_delete(obj) |
| 30 | |
| 31 | class XOSQt600Service(XOSResource): |
| 32 | provides = "tosca.nodes.Qt600Service" |
| 33 | xos_model = Qt600Service |
| 34 | copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber"] |
| 35 | |
| 36 | def postprocess(self, obj): |
| 37 | for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"): |
| 38 | provider_service = self.get_xos_object(Qt600Service, name=provider_service_name) |
| 39 | |
| 40 | existing_tenancy = CoarseTenant.get_tenant_objects().filter(provider_service = provider_service, subscriber_service = obj) |
| 41 | if existing_tenancy: |
| 42 | self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service))) |
| 43 | else: |
| 44 | tenancy = CoarseTenant(provider_service = provider_service, |
| 45 | subscriber_service = obj) |
| 46 | tenancy.save() |
| 47 | |
| 48 | self.info("Created Tenancy relationship from %s to %s" % (str(obj), str(provider_service))) |
| 49 | |
| 50 | def can_delete(self, obj): |
| 51 | if obj.slices.exists(): |
| 52 | self.info("Service %s has active slices; skipping delete" % obj.name) |
| 53 | return False |
| 54 | return super(XOSQt600Service, self).can_delete(obj) |
| 55 | |
| 56 | class XOSVpmaService(XOSResource): |
| 57 | provides = "tosca.nodes.VpmaService" |
| 58 | xos_model = VpmaService |
| 59 | copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber"] |
| 60 | |
| 61 | def postprocess(self, obj): |
| 62 | for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"): |
| 63 | provider_service = self.get_xos_object(VpmaService, name=provider_service_name) |
| 64 | |
| 65 | existing_tenancy = CoarseTenant.get_tenant_objects().filter(provider_service = provider_service, subscriber_service = obj) |
| 66 | if existing_tenancy: |
| 67 | self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service))) |
| 68 | else: |
| 69 | tenancy = CoarseTenant(provider_service = provider_service, |
| 70 | subscriber_service = obj) |
| 71 | tenancy.save() |
| 72 | |
| 73 | self.info("Created Tenancy relationship from %s to %s" % (str(obj), str(provider_service))) |
| 74 | |
| 75 | def can_delete(self, obj): |
| 76 | if obj.slices.exists(): |
| 77 | self.info("Service %s has active slices; skipping delete" % obj.name) |
| 78 | return False |
| 79 | return super(XOSVpmaService, self).can_delete(obj) |
| 80 | |
| 81 | class XOSVtaService(XOSResource): |
| 82 | provides = "tosca.nodes.VtaService" |
| 83 | xos_model = VtaService |
| 84 | copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber"] |
| 85 | |
| 86 | def postprocess(self, obj): |
| 87 | for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"): |
| 88 | provider_service = self.get_xos_object(VtaService, name=provider_service_name) |
| 89 | |
| 90 | existing_tenancy = CoarseTenant.get_tenant_objects().filter(provider_service = provider_service, subscriber_service = obj) |
| 91 | if existing_tenancy: |
| 92 | self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service))) |
| 93 | else: |
| 94 | tenancy = CoarseTenant(provider_service = provider_service, |
| 95 | subscriber_service = obj) |
| 96 | tenancy.save() |
| 97 | |
| 98 | self.info("Created Tenancy relationship from %s to %s" % (str(obj), str(provider_service))) |
| 99 | |
| 100 | def can_delete(self, obj): |
| 101 | if obj.slices.exists(): |
| 102 | self.info("Service %s has active slices; skipping delete" % obj.name) |
| 103 | return False |
| 104 | return super(XOSVtaService, self).can_delete(obj) |
| 105 | |