blob: 6c59ef63dcb9bcc8a3d0e1981d3e54b3a8dbcac7 [file] [log] [blame]
Matteo Scandolo80948f22018-04-20 17:02:31 +02001
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
17from xosapi.orm import ORMWrapper, register_convenience_wrapper
18from xosapi.convenience.serviceinstance import ORMWrapperServiceInstance
19
Matteo Scandoloe2cb8a42018-05-18 16:30:06 -070020import logging as log
Matteo Scandolo80948f22018-04-20 17:02:31 +020021
22class ORMWrapperVOLTServiceInstance(ORMWrapperServiceInstance):
23
Matteo Scandolo80948f22018-04-20 17:02:31 +020024 def get_olt_device_by_subscriber(self):
Matteo Scandoloe2cb8a42018-05-18 16:30:06 -070025 pon_port = self.get_pon_port_by_subscriber()
26 return pon_port.olt_device
27
28 def get_pon_port_by_subscriber(self):
Matteo Scandolo80948f22018-04-20 17:02:31 +020029 si = self.stub.ServiceInstance.objects.get(id=self.id)
Matteo Scandoloe2cb8a42018-05-18 16:30:06 -070030 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 Scandolo80948f22018-04-20 17:02:31 +020033
34 @property
Matteo Scandolo80948f22018-04-20 17:02:31 +020035 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 Scandoloe2cb8a42018-05-18 16:30:06 -070042 log.exception('Error while reading switch_datapath_id: %s' % e.message)
Matteo Scandolo80948f22018-04-20 17:02:31 +020043 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 Scandoloe2cb8a42018-05-18 16:30:06 -070053 log.exception('Error while reading switch_port: %s' % e.message)
Matteo Scandolo80948f22018-04-20 17:02:31 +020054 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 Scandoloe2cb8a42018-05-18 16:30:06 -070064 log.exception('Error while reading outer_tpid: %s' % e.message)
Matteo Scandolo80948f22018-04-20 17:02:31 +020065 return None
66
67
68register_convenience_wrapper("VOLTServiceInstance", ORMWrapperVOLTServiceInstance)