blob: f7f795f939e980e14a929a44333e7c610783bc02 [file] [log] [blame]
Andy Bavier561f3e52019-03-15 10:46:05 -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
18from xossynchronizer.event_steps.eventstep import EventStep
Andy Bavier289d7aa2019-04-25 10:00:28 -070019from helpers import TtHelpers
20
Andy Bavier561f3e52019-03-15 10:46:05 -070021
22class ONUEventStep(EventStep):
23 topics = ["onu.events"]
24 technology = "kafka"
25
26 max_onu_retry = 50
27
28 def __init__(self, *args, **kwargs):
29 super(ONUEventStep, self).__init__(*args, **kwargs)
30
Andy Bavier561f3e52019-03-15 10:46:05 -070031 def process_event(self, event):
32 value = json.loads(event.value)
33 self.log.info("onu.events: received event", value=value)
34
Andy Bavier0ce0dae2019-05-10 17:46:02 -070035 tt_si = TtHelpers.find_or_create_tt_si(self.model_accessor, self.log, value)
Andy Bavier561f3e52019-03-15 10:46:05 -070036 if value["status"] == "activated":
37 self.log.info("onu.events: activated onu", value=value)
Andy Bavier289d7aa2019-04-25 10:00:28 -070038 tt_si = TtHelpers.find_or_create_tt_si(self.model_accessor, self.log, value)
39 tt_si.no_sync = False
40 tt_si.uni_port_id = long(value["portNumber"])
41 tt_si.of_dpid = value["deviceId"]
Andy Bavier0ce0dae2019-05-10 17:46:02 -070042 tt_si.oper_onu_status = "ENABLED"
Andy Bavier561f3e52019-03-15 10:46:05 -070043 tt_si.save_changed_fields(always_update_timestamp=True)
44 elif value["status"] == "disabled":
Andy Bavier0ce0dae2019-05-10 17:46:02 -070045 self.log.info("onu.events: disabled onu, resetting the subscriber", value=value)
46 tt_si.oper_onu_status = "DISABLED"
47 tt_si.save_changed_fields(always_update_timestamp=True)
Andy Bavier561f3e52019-03-15 10:46:05 -070048 return
49 else:
50 self.log.warn("onu.events: Unknown status value: %s" % value["status"], value=value)
51 return