blob: 856d9906fb37af94519464a738839e1b040a45ac [file] [log] [blame]
Andy Bavier03df22b2017-08-30 14:46:02 -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
17from core.models import User, ServiceInstanceLink
18from services.volt.models import VOLTTenant, VOLTService, VOLT_KIND
19from services.rcord.models import CordSubscriberRoot
20
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:
34 args["owner"] = self.get_xos_object(VOLTService, throw_exception=throw_exception, name=provider_name)
35
36 return args
37
38 def get_existing_objs(self):
39 args = self.get_xos_args(throw_exception=False)
40 provider_service = args.get("owner", None)
41 service_specific_id = args.get("service_specific_id", None)
42 if (provider_service) and (service_specific_id):
43 existing_obj = self.get_xos_object(VOLTTenant, owner=provider_service, service_specific_id=service_specific_id, throw_exception=False)
44 if existing_obj:
45 return [ existing_obj ]
46 return []
47
48 def postprocess(self, obj):
49 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()
58
59 def can_delete(self, obj):
60 return super(XOSVOLTTenant, self).can_delete(obj)
61