Scott Baker | 3b8ceca | 2017-10-12 11:38:50 -0700 | [diff] [blame] | 1 | |
| 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 | |
| 17 | from xosapi.orm import ORMWrapper, register_convenience_wrapper |
| 18 | |
| 19 | class ORMWrapperVEEServiceInstance(ORMWrapper): |
| 20 | @property |
| 21 | def veg(self): |
| 22 | links = self.stub.ServiceInstanceLink.objects.filter(subscriber_service_instance_id = self.id) |
| 23 | for link in links: |
| 24 | # cast from ServiceInstance to VSGTenant |
| 25 | vegs = self.stub.VEGTenant.objects.filter(id = link.provider_service_instance.id) |
| 26 | if vegs: |
| 27 | return vegs[0] |
| 28 | return None |
| 29 | |
| 30 | # DEPRECATED |
| 31 | @property |
| 32 | def vcpe(self): |
| 33 | return self.veg |
| 34 | |
| 35 | # DEPRECATED |
| 36 | @property |
| 37 | def vsg(Self): |
| 38 | return self.veg |
| 39 | |
| 40 | @property |
| 41 | def subscriber(self): |
| 42 | links = self.stub.ServiceInstanceLink.objects.filter(provider_service_instance_id = self.id) |
| 43 | for link in links: |
| 44 | # assume the only thing that links to a VEE must be a subscriber |
| 45 | if link.subscriber_service_instance: |
| 46 | return link.subscriber_service_instance.leaf_model |
| 47 | return None |
| 48 | |
| 49 | register_convenience_wrapper("VEEServiceInstance", ORMWrapperVEEServiceInstance) |