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 | |
| 24 | @property |
| 25 | def vsg(self): |
| 26 | log.warning('VOLTServiceInstance.vsg is DEPRECATED, use get_westbound_service_instance_properties instead') |
| 27 | links = self.stub.ServiceInstanceLink.objects.filter(subscriber_service_instance_id = self.id) |
| 28 | for link in links: |
| 29 | # cast from ServiceInstance to VSGTenant |
| 30 | vsgs = self.stub.VSGServiceInstance.objects.filter(id = link.provider_service_instance.id) |
| 31 | if vsgs: |
| 32 | return vsgs[0] |
| 33 | return None |
| 34 | |
| 35 | # DEPRECATED |
| 36 | @property |
| 37 | def vcpe(self): |
| 38 | log.warning('VOLTServiceInstance.vcpe is DEPRECATED, use VOLTServiceInstance.vsg instead') |
| 39 | return self.vsg |
| 40 | |
| 41 | @property |
| 42 | def subscriber(self): |
| 43 | log.warning( |
| 44 | 'VOLTServiceInstance.subscriber is DEPRECATED, use get_westbound_service_instance_properties instead') |
| 45 | # NOTE this assume that each VOLT has just 1 subscriber, is that right? |
Matteo Scandolo | 7680a68 | 2018-05-16 14:16:11 -0700 | [diff] [blame] | 46 | try: |
| 47 | links = self.stub.ServiceInstanceLink.objects.filter(provider_service_instance_id = self.id) |
| 48 | for link in links: |
| 49 | subs = self.stub.ServiceInstance.objects.filter(id=link.subscriber_service_instance_id) |
| 50 | if subs: |
| 51 | return subs[0].leaf_model |
| 52 | return None |
| 53 | except Exception, e: |
| 54 | log.warning('Error while locating subscriber for vOLTServiceInstance with id %s: %s' % (self.id, e.message)) |
| 55 | return None |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 56 | |
| 57 | @property |
| 58 | def c_tag(self): |
| 59 | log.warning( |
| 60 | 'VOLTServiceInstance.c_tag is DEPRECATED, use get_westbound_service_instance_properties instead') |
| 61 | return self.subscriber.c_tag |
| 62 | |
| 63 | def get_olt_device_by_subscriber(self): |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 64 | pon_port = self.get_pon_port_by_subscriber() |
| 65 | return pon_port.olt_device |
| 66 | |
| 67 | def get_pon_port_by_subscriber(self): |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 68 | si = self.stub.ServiceInstance.objects.get(id=self.id) |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 69 | onu_sn = si.get_westbound_service_instance_properties("onu_device") |
| 70 | onu = self.stub.ONUDevice.objects.get(serial_number=onu_sn) |
| 71 | return onu.pon_port |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 72 | |
| 73 | @property |
| 74 | def s_tag(self): |
| 75 | try: |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 76 | pon_port = self.get_pon_port_by_subscriber() |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 77 | |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 78 | if pon_port: |
| 79 | return pon_port.s_tag |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 80 | return None |
| 81 | except Exception, e: |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 82 | log.exception('Error while reading s_tag: %s' % e.message) |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 83 | return None |
| 84 | |
| 85 | @property |
| 86 | def switch_datapath_id(self): |
| 87 | try: |
| 88 | olt_device = self.get_olt_device_by_subscriber() |
| 89 | if olt_device: |
| 90 | return olt_device.switch_datapath_id |
| 91 | return None |
| 92 | except Exception, e: |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 93 | log.exception('Error while reading switch_datapath_id: %s' % e.message) |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 94 | return None |
| 95 | |
| 96 | @property |
| 97 | def switch_port(self): |
| 98 | try: |
| 99 | olt_device = self.get_olt_device_by_subscriber() |
| 100 | if olt_device: |
| 101 | return olt_device.switch_port |
| 102 | return None |
| 103 | except Exception, e: |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 104 | log.exception('Error while reading switch_port: %s' % e.message) |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 105 | return None |
| 106 | |
| 107 | @property |
| 108 | def outer_tpid(self): |
| 109 | try: |
| 110 | olt_device = self.get_olt_device_by_subscriber() |
| 111 | if olt_device: |
| 112 | return olt_device.outer_tpid |
| 113 | return None |
| 114 | except Exception, e: |
Matteo Scandolo | e2cb8a4 | 2018-05-18 16:30:06 -0700 | [diff] [blame] | 115 | log.exception('Error while reading outer_tpid: %s' % e.message) |
Matteo Scandolo | 80948f2 | 2018-04-20 17:02:31 +0200 | [diff] [blame] | 116 | return None |
| 117 | |
| 118 | |
| 119 | register_convenience_wrapper("VOLTServiceInstance", ORMWrapperVOLTServiceInstance) |