Matteo Scandolo | 35113f7 | 2017-08-08 13:05:25 -0700 | [diff] [blame] | 1 | # 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 Williams | 1ce6c38 | 2016-10-05 18:02:09 -0700 | [diff] [blame] | 15 | from xosresource import XOSResource |
Scott Baker | 0982002 | 2017-07-18 11:29:59 -0700 | [diff] [blame] | 16 | from core.models import Service |
Scott Baker | ffac718 | 2017-07-27 15:21:30 -0700 | [diff] [blame] | 17 | from services.exampleservice.models import ExampleServiceInstance |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 18 | |
Scott Baker | ffac718 | 2017-07-27 15:21:30 -0700 | [diff] [blame] | 19 | class XOSExampleServiceInstance(XOSResource): |
| 20 | provides = ["tosca.nodes.ExampleServiceInstance", |
| 21 | "tosca.nodes.ExampleTenant" # deprecated |
| 22 | ] |
| 23 | xos_model = ExampleServiceInstance |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 24 | name_field = "service_specific_id" |
| 25 | copyin_props = ("tenant_message",) |
| 26 | |
| 27 | def get_xos_args(self, throw_exception=True): |
Scott Baker | ffac718 | 2017-07-27 15:21:30 -0700 | [diff] [blame] | 28 | args = super(XOSExampleServiceInstance, self).get_xos_args() |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 29 | |
Scott Baker | ffac718 | 2017-07-27 15:21:30 -0700 | [diff] [blame] | 30 | # ExampleServiceInstance must always have a provider_service |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 31 | provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True) |
| 32 | if provider_name: |
Scott Baker | 0982002 | 2017-07-18 11:29:59 -0700 | [diff] [blame] | 33 | args["owner"] = self.get_xos_object(Service, throw_exception=True, name=provider_name) |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 34 | |
| 35 | return args |
| 36 | |
| 37 | def get_existing_objs(self): |
| 38 | args = self.get_xos_args(throw_exception=False) |
Scott Baker | ffac718 | 2017-07-27 15:21:30 -0700 | [diff] [blame] | 39 | return ExampleServiceInstance.objects.filter(owner=args["owner"], service_specific_id=args["service_specific_id"]) |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 40 | return [] |
| 41 | |
| 42 | def can_delete(self, obj): |
Scott Baker | ffac718 | 2017-07-27 15:21:30 -0700 | [diff] [blame] | 43 | return super(XOSExampleServiceInstance, self).can_delete(obj) |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 44 | |