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 | copyin_props = ("tenant_message",) |
| 25 | |
| 26 | def get_xos_args(self, throw_exception=True): |
Scott Baker | ffac718 | 2017-07-27 15:21:30 -0700 | [diff] [blame] | 27 | args = super(XOSExampleServiceInstance, self).get_xos_args() |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 28 | |
Scott Baker | ffac718 | 2017-07-27 15:21:30 -0700 | [diff] [blame] | 29 | # ExampleServiceInstance must always have a provider_service |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 30 | provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True) |
| 31 | if provider_name: |
Scott Baker | 0982002 | 2017-07-18 11:29:59 -0700 | [diff] [blame] | 32 | 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] | 33 | |
| 34 | return args |
| 35 | |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 36 | def can_delete(self, obj): |
Scott Baker | ffac718 | 2017-07-27 15:21:30 -0700 | [diff] [blame] | 37 | return super(XOSExampleServiceInstance, self).can_delete(obj) |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 38 | |