blob: 1d6c76afd4f01c2784414080022efd7feabd850b [file] [log] [blame]
Matteo Scandolo35113f72017-08-08 13:05:25 -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
Zack Williams1ce6c382016-10-05 18:02:09 -070017from xosresource import XOSResource
Scott Baker09820022017-07-18 11:29:59 -070018from core.models import Service
Scott Baker619de672016-06-20 12:49:38 -070019from services.exampleservice.models import ExampleTenant, SERVICE_NAME as EXAMPLETENANT_KIND
20
Scott Baker619de672016-06-20 12:49:38 -070021class XOSExampleTenant(XOSResource):
22 provides = "tosca.nodes.ExampleTenant"
23 xos_model = ExampleTenant
24 name_field = "service_specific_id"
25 copyin_props = ("tenant_message",)
26
27 def get_xos_args(self, throw_exception=True):
28 args = super(XOSExampleTenant, self).get_xos_args()
29
30 # ExampleTenant must always have a provider_service
31 provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True)
32 if provider_name:
Scott Baker09820022017-07-18 11:29:59 -070033 args["owner"] = self.get_xos_object(Service, throw_exception=True, name=provider_name)
Scott Baker619de672016-06-20 12:49:38 -070034
35 return args
36
37 def get_existing_objs(self):
38 args = self.get_xos_args(throw_exception=False)
Scott Baker09820022017-07-18 11:29:59 -070039 return ExampleTenant.objects.filter(owner=args["owner"], service_specific_id=args["service_specific_id"])
Scott Baker619de672016-06-20 12:49:38 -070040 return []
41
42 def can_delete(self, obj):
43 return super(XOSExampleTenant, self).can_delete(obj)
44