blob: 48f52dc97148fa1efe08fabed9218b02cf6ae9f0 [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
20from xosconfig import Config
21from multistructlog import create_logger
22
23log = create_logger(Config().get('logging'))
24
25class ORMWrapperVOLTServiceInstance(ORMWrapperServiceInstance):
26
27 @property
28 def vsg(self):
29 log.warning('VOLTServiceInstance.vsg is DEPRECATED, use get_westbound_service_instance_properties instead')
30 links = self.stub.ServiceInstanceLink.objects.filter(subscriber_service_instance_id = self.id)
31 for link in links:
32 # cast from ServiceInstance to VSGTenant
33 vsgs = self.stub.VSGServiceInstance.objects.filter(id = link.provider_service_instance.id)
34 if vsgs:
35 return vsgs[0]
36 return None
37
38 # DEPRECATED
39 @property
40 def vcpe(self):
41 log.warning('VOLTServiceInstance.vcpe is DEPRECATED, use VOLTServiceInstance.vsg instead')
42 return self.vsg
43
44 @property
45 def subscriber(self):
46 log.warning(
47 'VOLTServiceInstance.subscriber is DEPRECATED, use get_westbound_service_instance_properties instead')
48 # NOTE this assume that each VOLT has just 1 subscriber, is that right?
Matteo Scandolo7680a682018-05-16 14:16:11 -070049 try:
50 links = self.stub.ServiceInstanceLink.objects.filter(provider_service_instance_id = self.id)
51 for link in links:
52 subs = self.stub.ServiceInstance.objects.filter(id=link.subscriber_service_instance_id)
53 if subs:
54 return subs[0].leaf_model
55 return None
56 except Exception, e:
57 log.warning('Error while locating subscriber for vOLTServiceInstance with id %s: %s' % (self.id, e.message))
58 return None
Matteo Scandolo80948f22018-04-20 17:02:31 +020059
60 @property
61 def c_tag(self):
62 log.warning(
63 'VOLTServiceInstance.c_tag is DEPRECATED, use get_westbound_service_instance_properties instead')
64 return self.subscriber.c_tag
65
66 def get_olt_device_by_subscriber(self):
67 si = self.stub.ServiceInstance.objects.get(id=self.id)
68
69 olt_device_name = si.get_westbound_service_instance_properties("olt_device")
70
71 olt_device = self.stub.OLTDevice.objects.get(name=olt_device_name)
72 return olt_device
73
74 def get_olt_port_by_subscriber(self):
75 si = self.stub.ServiceInstance.objects.get(id=self.id)
76
77 olt_port_name = si.get_westbound_service_instance_properties("olt_port")
78
79 olt_device = self.get_olt_device_by_subscriber()
80 olt_port = self.stub.PONPort.objects.get(name=olt_port_name, olt_device_id=olt_device.id)
81 return olt_port
82
83 @property
84 def s_tag(self):
85 try:
86 olt_port = self.get_olt_port_by_subscriber()
87
88 if olt_port:
89 return olt_port.s_tag
90 return None
91 except Exception, e:
92 log.warning('Error while reading s_tag: %s' % e.message)
93 return None
94
95 @property
96 def switch_datapath_id(self):
97 try:
98 olt_device = self.get_olt_device_by_subscriber()
99 if olt_device:
100 return olt_device.switch_datapath_id
101 return None
102 except Exception, e:
103 log.warning('Error while reading switch_datapath_id: %s' % e.message)
104 return None
105
106 @property
107 def switch_port(self):
108 try:
109 olt_device = self.get_olt_device_by_subscriber()
110 if olt_device:
111 return olt_device.switch_port
112 return None
113 except Exception, e:
114 log.warning('Error while reading switch_port: %s' % e.message)
115 return None
116
117 @property
118 def outer_tpid(self):
119 try:
120 olt_device = self.get_olt_device_by_subscriber()
121 if olt_device:
122 return olt_device.outer_tpid
123 return None
124 except Exception, e:
125 log.warning('Error while reading outer_tpid: %s' % e.message)
126 return None
127
128
129register_convenience_wrapper("VOLTServiceInstance", ORMWrapperVOLTServiceInstance)