blob: 0d51255aed613a6a2900187d2c026e7d880e997d [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
Scott Baker71d20472019-02-01 12:05:35 -080018from xossynchronizer.event_steps.eventstep import EventStep
Matteo Scandolo59e10fc2019-04-18 14:19:52 -070019from helpers import AttHelpers
Matteo Scandoloccef5782018-08-13 13:25:17 -070020
Scott Bakerc2a633d2019-04-01 19:27:41 -070021
Matteo Scandoloccef5782018-08-13 13:25:17 -070022class 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 Scandoloccef5782018-08-13 13:25:17 -070031 def process_event(self, event):
32 value = json.loads(event.value)
33 self.log.info("onu.events: received event", value=value)
34
Matteo Scandolo2d9f40d2019-04-19 08:38:10 -070035 att_si = AttHelpers.find_or_create_att_si(self.model_accessor, self.log, value)
Matteo Scandoloccef5782018-08-13 13:25:17 -070036 if value["status"] == "activated":
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070037 self.log.info("onu.events: activated onu", value=value)
Matteo Scandolo59e10fc2019-04-18 14:19:52 -070038 att_si.no_sync = False
39 att_si.uni_port_id = long(value["portNumber"])
40 att_si.of_dpid = value["deviceId"]
Matteo Scandolo2d9f40d2019-04-19 08:38:10 -070041 att_si.oper_onu_status = "ENABLED"
Matteo Scandolo4f041502019-03-01 11:57:03 -080042 att_si.save_changed_fields(always_update_timestamp=True)
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070043 elif value["status"] == "disabled":
Matteo Scandolo2d9f40d2019-04-19 08:38:10 -070044 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 Scandolo4f041502019-03-01 11:57:03 -080047 return
Matteo Scandoloea529092018-09-11 16:36:39 -070048 else:
Matteo Scandolo4f041502019-03-01 11:57:03 -080049 self.log.warn("onu.events: Unknown status value: %s" % value["status"], value=value)
50 return