blob: fdae09e48eec1125127b420c5e5ce8b3bd80c4b6 [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
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 Scandolo7680a682018-05-16 14:16:11 -070046 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 Scandolo80948f22018-04-20 17:02:31 +020056
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 Scandoloe2cb8a42018-05-18 16:30:06 -070064 pon_port = self.get_pon_port_by_subscriber()
65 return pon_port.olt_device
66
67 def get_pon_port_by_subscriber(self):
Matteo Scandolo80948f22018-04-20 17:02:31 +020068 si = self.stub.ServiceInstance.objects.get(id=self.id)
Matteo Scandoloe2cb8a42018-05-18 16:30:06 -070069 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 Scandolo80948f22018-04-20 17:02:31 +020072
73 @property
74 def s_tag(self):
75 try:
Matteo Scandoloe2cb8a42018-05-18 16:30:06 -070076 pon_port = self.get_pon_port_by_subscriber()
Matteo Scandolo80948f22018-04-20 17:02:31 +020077
Matteo Scandoloe2cb8a42018-05-18 16:30:06 -070078 if pon_port:
79 return pon_port.s_tag
Matteo Scandolo80948f22018-04-20 17:02:31 +020080 return None
81 except Exception, e:
Matteo Scandoloe2cb8a42018-05-18 16:30:06 -070082 log.exception('Error while reading s_tag: %s' % e.message)
Matteo Scandolo80948f22018-04-20 17:02:31 +020083 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 Scandoloe2cb8a42018-05-18 16:30:06 -070093 log.exception('Error while reading switch_datapath_id: %s' % e.message)
Matteo Scandolo80948f22018-04-20 17:02:31 +020094 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 Scandoloe2cb8a42018-05-18 16:30:06 -0700104 log.exception('Error while reading switch_port: %s' % e.message)
Matteo Scandolo80948f22018-04-20 17:02:31 +0200105 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 Scandoloe2cb8a42018-05-18 16:30:06 -0700115 log.exception('Error while reading outer_tpid: %s' % e.message)
Matteo Scandolo80948f22018-04-20 17:02:31 +0200116 return None
117
118
119register_convenience_wrapper("VOLTServiceInstance", ORMWrapperVOLTServiceInstance)