Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 1 | |
| 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 | |
| 17 | import json |
Scott Baker | 71d2047 | 2019-02-01 12:05:35 -0800 | [diff] [blame] | 18 | from xossynchronizer.event_steps.eventstep import EventStep |
Matteo Scandolo | 59e10fc | 2019-04-18 14:19:52 -0700 | [diff] [blame] | 19 | from helpers import AttHelpers |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 20 | |
Scott Baker | c2a633d | 2019-04-01 19:27:41 -0700 | [diff] [blame] | 21 | |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 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 | |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 31 | def process_event(self, event): |
| 32 | value = json.loads(event.value) |
| 33 | self.log.info("onu.events: received event", value=value) |
| 34 | |
Matteo Scandolo | 2d9f40d | 2019-04-19 08:38:10 -0700 | [diff] [blame] | 35 | att_si = AttHelpers.find_or_create_att_si(self.model_accessor, self.log, value) |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 36 | if value["status"] == "activated": |
Matteo Scandolo | e8c33d6 | 2018-08-16 14:37:24 -0700 | [diff] [blame] | 37 | self.log.info("onu.events: activated onu", value=value) |
Matteo Scandolo | 59e10fc | 2019-04-18 14:19:52 -0700 | [diff] [blame] | 38 | att_si.no_sync = False |
| 39 | att_si.uni_port_id = long(value["portNumber"]) |
| 40 | att_si.of_dpid = value["deviceId"] |
Matteo Scandolo | 2d9f40d | 2019-04-19 08:38:10 -0700 | [diff] [blame] | 41 | att_si.oper_onu_status = "ENABLED" |
Matteo Scandolo | 4f04150 | 2019-03-01 11:57:03 -0800 | [diff] [blame] | 42 | att_si.save_changed_fields(always_update_timestamp=True) |
Matteo Scandolo | e8c33d6 | 2018-08-16 14:37:24 -0700 | [diff] [blame] | 43 | elif value["status"] == "disabled": |
Matteo Scandolo | 2d9f40d | 2019-04-19 08:38:10 -0700 | [diff] [blame] | 44 | self.log.info("onu.events: disabled onu, resetting the subscriber", value=value) |
| 45 | att_si.oper_onu_status = "DISABLED" |
| 46 | att_si.save_changed_fields(always_update_timestamp=True) |
Matteo Scandolo | 4f04150 | 2019-03-01 11:57:03 -0800 | [diff] [blame] | 47 | return |
Matteo Scandolo | ea52909 | 2018-09-11 16:36:39 -0700 | [diff] [blame] | 48 | else: |
Matteo Scandolo | 4f04150 | 2019-03-01 11:57:03 -0800 | [diff] [blame] | 49 | self.log.warn("onu.events: Unknown status value: %s" % value["status"], value=value) |
| 50 | return |