blob: 7090be38a434400b1bd05c74e43b07a1c28d8a2e [file] [log] [blame]
Andy Bavier0c564b32017-10-12 13:04:11 -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
15from xosresource import XOSResource
16from core.models import Service
17from services.internetemulator.models import InternetEmulatorServiceInstance
18
19class XOSInternetEmulatorServiceInstance(XOSResource):
20 provides = ["tosca.nodes.InternetEmulatorServiceInstance"]
21 xos_model = InternetEmulatorServiceInstance
22 name_field = "service_specific_id"
23
24 def get_xos_args(self, throw_exception=True):
25 args = super(XOSInternetEmulatorServiceInstance, self).get_xos_args()
26
27 provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True)
28 if provider_name:
29 args["owner"] = self.get_xos_object(Service, throw_exception=True, name=provider_name)
30
31 return args
32
33 def get_existing_objs(self):
34 args = self.get_xos_args(throw_exception=False)
35 return InternetEmulatorServiceInstance.objects.filter(owner=args["owner"], service_specific_id=args["service_specific_id"])
36 return []
37
38 def can_delete(self, obj):
39 return super(XOSInternetEmulatorServiceInstance, self).can_delete(obj)
40