Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [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 | from xosapi.convenience.serviceinstance import ORMWrapperServiceInstance |
| 19 | |
| 20 | from xosconfig import Config |
| 21 | from multistructlog import create_logger |
| 22 | |
| 23 | log = create_logger(Config().get('logging')) |
| 24 | |
| 25 | class ORMWrapperVOLTServiceInstance(ORMWrapperServiceInstance): |
| 26 | |
| 27 | @property |
| 28 | def vsg(self): |
| 29 | log.warning('VOLTServiceInstance.vsg is DEPRECATED, use get_westbound_service_instance_properties instead') |
| 30 | links = self.stub.ServiceInstanceLink.objects.filter(subscriber_service_instance_id = self.id) |
| 31 | for link in links: |
| 32 | # cast from ServiceInstance to VSGTenant |
| 33 | vsgs = self.stub.VSGServiceInstance.objects.filter(id = link.provider_service_instance.id) |
| 34 | if vsgs: |
| 35 | return vsgs[0] |
| 36 | return None |
| 37 | |
| 38 | # DEPRECATED |
| 39 | @property |
| 40 | def vcpe(self): |
| 41 | log.warning('VOLTServiceInstance.vcpe is DEPRECATED, use VOLTServiceInstance.vsg instead') |
| 42 | return self.vsg |
| 43 | |
| 44 | @property |
| 45 | def subscriber(self): |
| 46 | log.warning( |
| 47 | 'VOLTServiceInstance.subscriber is DEPRECATED, use get_westbound_service_instance_properties instead') |
| 48 | # NOTE this assume that each VOLT has just 1 subscriber, is that right? |
| 49 | links = self.stub.ServiceInstanceLink.objects.filter(provider_service_instance_id = self.id) |
| 50 | for link in links: |
| 51 | subs = self.stub.CordSubscriberRoot.objects.filter(id=link.subscriber_service_instance_id) |
| 52 | if subs: |
| 53 | return subs[0] |
| 54 | return None |
| 55 | |
| 56 | @property |
| 57 | def c_tag(self): |
| 58 | log.warning( |
| 59 | 'VOLTServiceInstance.c_tag is DEPRECATED, use get_westbound_service_instance_properties instead') |
| 60 | return self.subscriber.c_tag |
| 61 | |
| 62 | def get_olt_device_by_subscriber(self): |
| 63 | si = self.stub.ServiceInstance.objects.get(id=self.id) |
| 64 | |
| 65 | olt_device_name = si.get_westbound_service_instance_properties("olt_device") |
| 66 | |
| 67 | olt_device = self.stub.OLTDevice.objects.get(name=olt_device_name) |
| 68 | return olt_device |
| 69 | |
| 70 | def get_olt_port_by_subscriber(self): |
| 71 | si = self.stub.ServiceInstance.objects.get(id=self.id) |
| 72 | |
| 73 | olt_port_name = si.get_westbound_service_instance_properties("olt_port") |
| 74 | |
| 75 | olt_device = self.get_olt_device_by_subscriber() |
| 76 | olt_port = self.stub.PONPort.objects.get(name=olt_port_name, olt_device_id=olt_device.id) |
| 77 | return olt_port |
| 78 | |
| 79 | @property |
| 80 | def s_tag(self): |
| 81 | try: |
| 82 | olt_port = self.get_olt_port_by_subscriber() |
| 83 | |
| 84 | if olt_port: |
| 85 | return olt_port.s_tag |
| 86 | return None |
| 87 | except Exception, e: |
| 88 | log.warning('Error while reading s_tag: %s' % e.message) |
| 89 | return None |
| 90 | |
| 91 | @property |
| 92 | def switch_datapath_id(self): |
| 93 | try: |
| 94 | olt_device = self.get_olt_device_by_subscriber() |
| 95 | if olt_device: |
| 96 | return olt_device.switch_datapath_id |
| 97 | return None |
| 98 | except Exception, e: |
| 99 | log.warning('Error while reading switch_datapath_id: %s' % e.message) |
| 100 | return None |
| 101 | |
| 102 | @property |
| 103 | def switch_port(self): |
| 104 | try: |
| 105 | olt_device = self.get_olt_device_by_subscriber() |
| 106 | if olt_device: |
| 107 | return olt_device.switch_port |
| 108 | return None |
| 109 | except Exception, e: |
| 110 | log.warning('Error while reading switch_port: %s' % e.message) |
| 111 | return None |
| 112 | |
| 113 | @property |
| 114 | def outer_tpid(self): |
| 115 | try: |
| 116 | olt_device = self.get_olt_device_by_subscriber() |
| 117 | if olt_device: |
| 118 | return olt_device.outer_tpid |
| 119 | return None |
| 120 | except Exception, e: |
| 121 | log.warning('Error while reading outer_tpid: %s' % e.message) |
| 122 | return None |
| 123 | |
| 124 | |
| 125 | register_convenience_wrapper("VOLTServiceInstance", ORMWrapperVOLTServiceInstance) |