blob: 856d9906fb37af94519464a738839e1b040a45ac [file] [log] [blame]
Matteo Scandolo5e293c92017-08-08 13:05:23 -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
Scott Bakerd7590f72017-07-18 11:37:22 -070017from core.models import User, ServiceInstanceLink
Scott Bakerc15556d2017-05-06 09:55:01 -070018from services.volt.models import VOLTTenant, VOLTService, VOLT_KIND
19from services.rcord.models import CordSubscriberRoot
Scott Baker8e6647a2016-06-20 17:16:20 -070020
21from xosresource import XOSResource
22
23class XOSVOLTTenant(XOSResource):
24 provides = "tosca.nodes.VOLTTenant"
25 xos_model = VOLTTenant
26 copyin_props = ["service_specific_id", "s_tag", "c_tag"]
27 name_field = None
28
29 def get_xos_args(self, throw_exception=True):
30 args = super(XOSVOLTTenant, self).get_xos_args()
31
32 provider_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
33 if provider_name:
Scott Bakerd7590f72017-07-18 11:37:22 -070034 args["owner"] = self.get_xos_object(VOLTService, throw_exception=throw_exception, name=provider_name)
Scott Baker8e6647a2016-06-20 17:16:20 -070035
36 return args
37
38 def get_existing_objs(self):
39 args = self.get_xos_args(throw_exception=False)
Scott Bakerd7590f72017-07-18 11:37:22 -070040 provider_service = args.get("owner", None)
Scott Baker8e6647a2016-06-20 17:16:20 -070041 service_specific_id = args.get("service_specific_id", None)
42 if (provider_service) and (service_specific_id):
Scott Bakerd7590f72017-07-18 11:37:22 -070043 existing_obj = self.get_xos_object(VOLTTenant, owner=provider_service, service_specific_id=service_specific_id, throw_exception=False)
Scott Baker8e6647a2016-06-20 17:16:20 -070044 if existing_obj:
45 return [ existing_obj ]
46 return []
47
48 def postprocess(self, obj):
Scott Bakerd7590f72017-07-18 11:37:22 -070049 subscriber_name = self.get_requirement("tosca.relationships.BelongsToSubscriber")
50 if subscriber_name:
51 subscriber = self.get_xos_object(CordSubscriberRoot, throw_exception=True, name=subscriber_name)
52
53 links = ServiceInstanceLink.objects.filter(provider_service_instance = obj,
54 subscriber_service_instance = subscriber)
55 if not links:
56 link = ServiceInstanceLink(provider_service_instance = obj, subscriber_service_instance = subscriber)
57 link.save()
Scott Baker8e6647a2016-06-20 17:16:20 -070058
59 def can_delete(self, obj):
60 return super(XOSVOLTTenant, self).can_delete(obj)
61