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 | |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 20 | import logging as log |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 21 | |
| 22 | class ORMWrapperVOLTServiceInstance(ORMWrapperServiceInstance): |
| 23 | |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 24 | def get_olt_device_by_subscriber(self): |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 25 | pon_port = self.get_pon_port_by_subscriber() |
| 26 | return pon_port.olt_device |
| 27 | |
| 28 | def get_pon_port_by_subscriber(self): |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 29 | si = self.stub.ServiceInstance.objects.get(id=self.id) |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 30 | onu_sn = si.get_westbound_service_instance_properties("onu_device") |
| 31 | onu = self.stub.ONUDevice.objects.get(serial_number=onu_sn) |
| 32 | return onu.pon_port |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 33 | |
| 34 | @property |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 35 | def switch_datapath_id(self): |
| 36 | try: |
| 37 | olt_device = self.get_olt_device_by_subscriber() |
| 38 | if olt_device: |
| 39 | return olt_device.switch_datapath_id |
| 40 | return None |
| 41 | except Exception, e: |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 42 | log.exception('Error while reading switch_datapath_id: %s' % e.message) |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 43 | return None |
| 44 | |
| 45 | @property |
| 46 | def switch_port(self): |
| 47 | try: |
| 48 | olt_device = self.get_olt_device_by_subscriber() |
| 49 | if olt_device: |
| 50 | return olt_device.switch_port |
| 51 | return None |
| 52 | except Exception, e: |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 53 | log.exception('Error while reading switch_port: %s' % e.message) |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 54 | return None |
| 55 | |
| 56 | @property |
| 57 | def outer_tpid(self): |
| 58 | try: |
| 59 | olt_device = self.get_olt_device_by_subscriber() |
| 60 | if olt_device: |
| 61 | return olt_device.outer_tpid |
| 62 | return None |
| 63 | except Exception, e: |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 64 | log.exception('Error while reading outer_tpid: %s' % e.message) |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 65 | return None |
| 66 | |
| 67 | |
| 68 | register_convenience_wrapper("VOLTServiceInstance", ORMWrapperVOLTServiceInstance) |