blob: a7658f2e958588b56e85e1ffa6bee4b9fc4edfcc [file] [log] [blame]
Matteo Scandolo85f54982018-05-18 11:33:35 -07001
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
17import json
18import os
19import sys
20from synchronizers.new_base.eventstep import EventStep
21from synchronizers.new_base.modelaccessor import VOLTService, ONUDevice, Service, model_accessor
22
23# from xos.exceptions import XOSValidationError
24
Matteo Scandolo85f54982018-05-18 11:33:35 -070025class ONUEventStep(EventStep):
26 topics = ["onu.events"]
27 technology = "kafka"
28
29 def __init__(self, *args, **kwargs):
30 super(ONUEventStep, self).__init__(*args, **kwargs)
31
32 def get_oss_service(self, onu_serial_number):
33 try:
34 onu = ONUDevice.objects.get(serial_number=onu_serial_number)
35 except IndexError as e:
Matteo Scandolo7db85372018-05-22 15:26:55 -070036 # TODO create ONU if it does not exists
Matteo Scandolo85f54982018-05-18 11:33:35 -070037 raise Exception("No ONUDevice with serial_number %s is present in XOS" % onu_serial_number)
38
39 volt_service = onu.pon_port.olt_device.volt_service
40 service = Service.objects.get(id=volt_service.id)
Matteo Scandolo7db85372018-05-22 15:26:55 -070041 osses = [s for s in service.subscriber_services if s.kind.lower() == "oss"]
Matteo Scandolo85f54982018-05-18 11:33:35 -070042
43 if len(osses) > 1:
44 self.log.warn("More than one OSS found for %s" % volt_service.name)
45 try:
46 return osses[0].leaf_model
47 except IndexError as e:
48 return None
49
50 def handle_onu_activate_event(self, event):
51 oss = self.get_oss_service(event["serial_number"])
52
53 if not oss:
54 self.log.info("Not processing events as no OSS service is present (is it a provider of vOLT?")
55 else:
56 try:
57 oss.validate_onu(event)
58 except Exception, e:
59 self.log.exception("Failing to validate ONU in OSS Service %s" % oss.name)
60 raise e
61
62 def process_event(self, event):
63 value = json.loads(event.value)
64 self.log.info("onu.events: received event", value=value)
65
Matteo Scandolo7db85372018-05-22 15:26:55 -070066 if value["status"] == "activated":
Matteo Scandolo85f54982018-05-18 11:33:35 -070067 self.log.info("onu.events: activate onu", value=value)
68 self.handle_onu_activate_event(value)
69