blob: 7b8f640f2be9451a0425c3317f2d908f6462a3d0 [file] [log] [blame]
Matteo Scandolo35113f72017-08-08 13:05:25 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Zack Williams1ce6c382016-10-05 18:02:09 -070015from xosresource import XOSResource
Scott Baker09820022017-07-18 11:29:59 -070016from core.models import Service
Scott Bakerffac7182017-07-27 15:21:30 -070017from services.exampleservice.models import ExampleServiceInstance
Scott Baker619de672016-06-20 12:49:38 -070018
Scott Bakerffac7182017-07-27 15:21:30 -070019class XOSExampleServiceInstance(XOSResource):
20 provides = ["tosca.nodes.ExampleServiceInstance",
21 "tosca.nodes.ExampleTenant" # deprecated
22 ]
23 xos_model = ExampleServiceInstance
Scott Baker619de672016-06-20 12:49:38 -070024 name_field = "service_specific_id"
25 copyin_props = ("tenant_message",)
26
27 def get_xos_args(self, throw_exception=True):
Scott Bakerffac7182017-07-27 15:21:30 -070028 args = super(XOSExampleServiceInstance, self).get_xos_args()
Scott Baker619de672016-06-20 12:49:38 -070029
Scott Bakerffac7182017-07-27 15:21:30 -070030 # ExampleServiceInstance must always have a provider_service
Scott Baker619de672016-06-20 12:49:38 -070031 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 Bakerffac7182017-07-27 15:21:30 -070039 return ExampleServiceInstance.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):
Scott Bakerffac7182017-07-27 15:21:30 -070043 return super(XOSExampleServiceInstance, self).can_delete(obj)
Scott Baker619de672016-06-20 12:49:38 -070044