Daniele Moro | 134b8d6 | 2020-01-14 11:32:05 -0800 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2020-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 | |
| 17 | import json |
| 18 | from xossynchronizer.event_steps.eventstep import EventStep |
| 19 | from helpers import DtHelpers |
| 20 | |
| 21 | |
| 22 | class 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 | |
| 31 | def process_event(self, event): |
| 32 | value = json.loads(event.value) |
| 33 | self.log.info("onu.events: received event", value=value) |
| 34 | |
| 35 | dt_si = DtHelpers.find_or_create_dt_si(self.model_accessor, self.log, value) |
| 36 | if value["status"] == "activated": |
| 37 | self.log.info("onu.events: activated onu", value=value) |
| 38 | dt_si.no_sync = False |
| 39 | dt_si.uni_port_id = long(value["portNumber"]) |
| 40 | dt_si.of_dpid = value["deviceId"] |
| 41 | dt_si.oper_onu_status = "ENABLED" |
| 42 | dt_si.save_changed_fields(always_update_timestamp=True) |
| 43 | elif value["status"] == "disabled": |
| 44 | self.log.info("onu.events: disabled onu, resetting the subscriber", value=value) |
| 45 | dt_si.oper_onu_status = "DISABLED" |
| 46 | dt_si.save_changed_fields(always_update_timestamp=True) |
| 47 | return |
| 48 | else: |
| 49 | self.log.warn("onu.events: Unknown status value: %s" % value["status"], value=value) |
| 50 | return |