blob: 5e4339b3add99c3b99fa75df697f329b4dc5404d [file] [log] [blame]
Matteo Scandolo41ed0992017-08-08 13:05:27 -07001
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
JianHaoce45e042017-01-16 11:06:29 +000017from services.vsgw.models import VSGWService
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070018from xosresource import XOSResource
JianHaoce45e042017-01-16 11:06:29 +000019from service import XOSService
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070020
21class 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