Matteo Scandolo | 41ed099 | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame] | 17 | from services.vsgw.models import VSGWService |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 18 | from xosresource import XOSResource |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame] | 19 | from service import XOSService |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 20 | |
| 21 | class XOSVSGWService(XOSResource): |
| 22 | provides = "tosca.nodes.VSGWService" |
| 23 | xos_model = VSGWService |
| 24 | copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber", "service_message"] |
| 25 | |
| 26 | def postprocess(self, obj): |
| 27 | for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"): |
| 28 | provider_service = self.get_xos_object(VSGWService, name=provider_service_name) |
| 29 | |
| 30 | existing_tenancy = CoarseTenant.get_tenant_objects().filter(provider_service = provider_service, subscriber_service = obj) |
| 31 | if existing_tenancy: |
| 32 | self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service))) |
| 33 | else: |
| 34 | tenancy = CoarseTenant(provider_service = provider_service, |
| 35 | subscriber_service = obj) |
| 36 | tenancy.save() |
| 37 | |
| 38 | self.info("Created Tenancy relationship from %s to %s" % (str(obj), str(provider_service))) |
| 39 | |
| 40 | def can_delete(self, obj): |
| 41 | if obj.slices.exists(): |
| 42 | self.info("Service %s has active slices; skipping delete" % obj.name) |
| 43 | return False |
| 44 | return super(XOSVSGWService, self).can_delete(obj) |
| 45 | |