[CORD-2938] Moving VOLTServiceInstance conveniente method
Change-Id: Ia4d1256a1a2715e13a4c47c98d18bd6048a91ede
diff --git a/xos/synchronizer/models/convenience/voltserviceinstance.py b/xos/synchronizer/models/convenience/voltserviceinstance.py
new file mode 100644
index 0000000..dc87b6c
--- /dev/null
+++ b/xos/synchronizer/models/convenience/voltserviceinstance.py
@@ -0,0 +1,125 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from xosapi.orm import ORMWrapper, register_convenience_wrapper
+from xosapi.convenience.serviceinstance import ORMWrapperServiceInstance
+
+from xosconfig import Config
+from multistructlog import create_logger
+
+log = create_logger(Config().get('logging'))
+
+class ORMWrapperVOLTServiceInstance(ORMWrapperServiceInstance):
+
+ @property
+ def vsg(self):
+ log.warning('VOLTServiceInstance.vsg is DEPRECATED, use get_westbound_service_instance_properties instead')
+ links = self.stub.ServiceInstanceLink.objects.filter(subscriber_service_instance_id = self.id)
+ for link in links:
+ # cast from ServiceInstance to VSGTenant
+ vsgs = self.stub.VSGServiceInstance.objects.filter(id = link.provider_service_instance.id)
+ if vsgs:
+ return vsgs[0]
+ return None
+
+ # DEPRECATED
+ @property
+ def vcpe(self):
+ log.warning('VOLTServiceInstance.vcpe is DEPRECATED, use VOLTServiceInstance.vsg instead')
+ return self.vsg
+
+ @property
+ def subscriber(self):
+ log.warning(
+ 'VOLTServiceInstance.subscriber is DEPRECATED, use get_westbound_service_instance_properties instead')
+ # NOTE this assume that each VOLT has just 1 subscriber, is that right?
+ links = self.stub.ServiceInstanceLink.objects.filter(provider_service_instance_id = self.id)
+ for link in links:
+ subs = self.stub.CordSubscriberRoot.objects.filter(id=link.subscriber_service_instance_id)
+ if subs:
+ return subs[0]
+ return None
+
+ @property
+ def c_tag(self):
+ log.warning(
+ 'VOLTServiceInstance.c_tag is DEPRECATED, use get_westbound_service_instance_properties instead')
+ return self.subscriber.c_tag
+
+ def get_olt_device_by_subscriber(self):
+ si = self.stub.ServiceInstance.objects.get(id=self.id)
+
+ olt_device_name = si.get_westbound_service_instance_properties("olt_device")
+
+ olt_device = self.stub.OLTDevice.objects.get(name=olt_device_name)
+ return olt_device
+
+ def get_olt_port_by_subscriber(self):
+ si = self.stub.ServiceInstance.objects.get(id=self.id)
+
+ olt_port_name = si.get_westbound_service_instance_properties("olt_port")
+
+ olt_device = self.get_olt_device_by_subscriber()
+ olt_port = self.stub.PONPort.objects.get(name=olt_port_name, olt_device_id=olt_device.id)
+ return olt_port
+
+ @property
+ def s_tag(self):
+ try:
+ olt_port = self.get_olt_port_by_subscriber()
+
+ if olt_port:
+ return olt_port.s_tag
+ return None
+ except Exception, e:
+ log.warning('Error while reading s_tag: %s' % e.message)
+ return None
+
+ @property
+ def switch_datapath_id(self):
+ try:
+ olt_device = self.get_olt_device_by_subscriber()
+ if olt_device:
+ return olt_device.switch_datapath_id
+ return None
+ except Exception, e:
+ log.warning('Error while reading switch_datapath_id: %s' % e.message)
+ return None
+
+ @property
+ def switch_port(self):
+ try:
+ olt_device = self.get_olt_device_by_subscriber()
+ if olt_device:
+ return olt_device.switch_port
+ return None
+ except Exception, e:
+ log.warning('Error while reading switch_port: %s' % e.message)
+ return None
+
+ @property
+ def outer_tpid(self):
+ try:
+ olt_device = self.get_olt_device_by_subscriber()
+ if olt_device:
+ return olt_device.outer_tpid
+ return None
+ except Exception, e:
+ log.warning('Error while reading outer_tpid: %s' % e.message)
+ return None
+
+
+register_convenience_wrapper("VOLTServiceInstance", ORMWrapperVOLTServiceInstance)