blob: 045198f40246635dd49c55c90a7e63309f3ad4cf [file] [log] [blame]
Matteo Scandoloccef5782018-08-13 13:25:17 -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 time
19import os
20import sys
21from synchronizers.new_base.eventstep import EventStep
22from synchronizers.new_base.modelaccessor import AttWorkflowDriverServiceInstance, model_accessor
23
24class ONUEventStep(EventStep):
25 topics = ["onu.events"]
26 technology = "kafka"
27
28 max_onu_retry = 50
29
30 def __init__(self, *args, **kwargs):
31 super(ONUEventStep, self).__init__(*args, **kwargs)
32
33 def handle_onu_activate_event(self, event):
34
35 # NOTE do we need to wait of the ONU to be there?
36
37 self.log.info("onu.events: validating ONU %s" % event["serial_number"], event_data=event)
38
39 try:
40 att_si = AttWorkflowDriverServiceInstance.objects.get(serial_number=event["serial_number"])
41 att_si.no_sync = False;
42 self.log.debug("onu.events: Found existing AttWorkflowDriverServiceInstance", si=att_si)
43 except IndexError:
44 # create an AttWorkflowDriverServiceInstance, the validation will be triggered in the corresponding sync step
45 att_si = AttWorkflowDriverServiceInstance(
46 serial_number=event["serial_number"],
Matteo Scandolo53da44c2018-08-14 16:04:18 -070047 of_dpid=event["of_dpid"],
48 uni_port_id=event["uni_port_id"]
Matteo Scandoloccef5782018-08-13 13:25:17 -070049 )
50 self.log.debug("onu.events: Created new AttWorkflowDriverServiceInstance", si=att_si)
51 att_si.save()
52
53 def process_event(self, event):
54 value = json.loads(event.value)
55 self.log.info("onu.events: received event", value=value)
56
57 if value["status"] == "activated":
58 self.log.info("onu.events: activate onu", value=value)
59 self.handle_onu_activate_event(value)
60