Matteo Scandolo | 72f43d0 | 2018-07-16 10:54:01 -0400 | [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.service import ORMWrapperService |
| 19 | |
| 20 | import logging as log |
| 21 | |
| 22 | class ORMWrapperVOLTService(ORMWrapperService): |
| 23 | |
| 24 | def get_onu_sn_from_openflow(self, dp_id, port_no): |
| 25 | """Return the ONU serial number from logical_device informations |
| 26 | |
| 27 | example usage: |
| 28 | volt = VOLTService.objects.first() |
| 29 | sn = volt.get_onu_from_openflow("of:0000000ce2314000", 2) |
| 30 | # BRCM1234 |
| 31 | |
| 32 | Arguments: |
| 33 | dp_id {string} -- The openflow id of the OLT device |
| 34 | port_no {int} -- The openflow port id (UNI Port) |
| 35 | |
| 36 | Returns: |
| 37 | string -- ONU Serial Number |
| 38 | """ |
| 39 | |
| 40 | log.debug("Searching ONUDevice for %s:%s", (dp_id, port_no)) |
| 41 | print "Searching ONUDevice for %s:%s", (dp_id, port_no) |
| 42 | try: |
| 43 | olt = self.stub.OLTDevice.objects.get(dp_id=dp_id) |
| 44 | uni_ports = self.stub.UNIPort.objects.filter(port_no=port_no) |
| 45 | onu = [o.onu_device for o in uni_ports if o.onu_device.pon_port.olt_device.id == olt.id][0] |
| 46 | return onu.serial_number |
| 47 | except IndexError: |
| 48 | log.error("Can't find ONU for %s:%s", (dp_id, port_no)) |
| 49 | except Exception: |
| 50 | log.exception("Error while finding ONUDevice for %s:%s", (dp_id, port_no)) |
| 51 | |
| 52 | register_convenience_wrapper("VOLTService", ORMWrapperVOLTService) |