blob: 22f418891f3fac5fac2974c0e6fe3a9a6fad54e1 [file] [log] [blame]
Matteo Scandolo72f43d02018-07-16 10:54:01 -04001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Matteo Scandolo72f43d02018-07-16 10:54:01 -040015from xosapi.orm import ORMWrapper, register_convenience_wrapper
16from xosapi.convenience.service import ORMWrapperService
17
18import logging as log
19
Zack Williamsf19a6102018-11-02 10:52:15 -070020
Matteo Scandolo72f43d02018-07-16 10:54:01 -040021class ORMWrapperVOLTService(ORMWrapperService):
22
23 def get_onu_sn_from_openflow(self, dp_id, port_no):
24 """Return the ONU serial number from logical_device informations
Zack Williamsf19a6102018-11-02 10:52:15 -070025
Matteo Scandolo72f43d02018-07-16 10:54:01 -040026 example usage:
27 volt = VOLTService.objects.first()
28 sn = volt.get_onu_from_openflow("of:0000000ce2314000", 2)
29 # BRCM1234
30
31 Arguments:
32 dp_id {string} -- The openflow id of the OLT device
33 port_no {int} -- The openflow port id (UNI Port)
Zack Williamsf19a6102018-11-02 10:52:15 -070034
Matteo Scandolo72f43d02018-07-16 10:54:01 -040035 Returns:
36 string -- ONU Serial Number
37 """
38
Zack Williamsf19a6102018-11-02 10:52:15 -070039 log.debug("Searching ONUDevice for %s:%s" % (dp_id, port_no))
Matteo Scandolo72f43d02018-07-16 10:54:01 -040040 try:
41 olt = self.stub.OLTDevice.objects.get(dp_id=dp_id)
42 uni_ports = self.stub.UNIPort.objects.filter(port_no=port_no)
43 onu = [o.onu_device for o in uni_ports if o.onu_device.pon_port.olt_device.id == olt.id][0]
44 return onu.serial_number
45 except IndexError:
Zack Williamsf19a6102018-11-02 10:52:15 -070046 log.error("Can't find ONU for %s:%s" % (dp_id, port_no))
Matteo Scandolo72f43d02018-07-16 10:54:01 -040047 except Exception:
Zack Williamsf19a6102018-11-02 10:52:15 -070048 log.exception("Error while finding ONUDevice for %s:%s" % (dp_id, port_no))
Matteo Scandolo72f43d02018-07-16 10:54:01 -040049
Zack Williamsf19a6102018-11-02 10:52:15 -070050
51register_convenience_wrapper("VOLTService", ORMWrapperVOLTService)