blob: bae496dcd37047eece53602b4dfc973c414f19ef [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 Scandoloccef5782018-08-13 13:25:17 -070019
20class ONUEventStep(EventStep):
21 topics = ["onu.events"]
22 technology = "kafka"
23
24 max_onu_retry = 50
25
26 def __init__(self, *args, **kwargs):
27 super(ONUEventStep, self).__init__(*args, **kwargs)
28
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070029 def get_att_si(self, event):
Matteo Scandoloccef5782018-08-13 13:25:17 -070030 try:
Scott Baker71d20472019-02-01 12:05:35 -080031 att_si = self.model_accessor.AttWorkflowDriverServiceInstance.objects.get(serial_number=event["serial_number"])
Matteo Scandoloccef5782018-08-13 13:25:17 -070032 att_si.no_sync = False;
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070033 att_si.uni_port_id = event["uni_port_id"]
34 att_si.of_dpid = event["of_dpid"]
Matteo Scandoloccef5782018-08-13 13:25:17 -070035 self.log.debug("onu.events: Found existing AttWorkflowDriverServiceInstance", si=att_si)
36 except IndexError:
37 # create an AttWorkflowDriverServiceInstance, the validation will be triggered in the corresponding sync step
Scott Baker71d20472019-02-01 12:05:35 -080038 att_si = self.model_accessor.AttWorkflowDriverServiceInstance(
Matteo Scandoloccef5782018-08-13 13:25:17 -070039 serial_number=event["serial_number"],
Matteo Scandolo53da44c2018-08-14 16:04:18 -070040 of_dpid=event["of_dpid"],
Matteo Scandolo242c2962018-08-28 16:50:47 -070041 uni_port_id=event["uni_port_id"],
Scott Baker71d20472019-02-01 12:05:35 -080042 owner=self.model_accessor.AttWorkflowDriverService.objects.first() # we assume there is only one AttWorkflowDriverService
Matteo Scandoloccef5782018-08-13 13:25:17 -070043 )
44 self.log.debug("onu.events: Created new AttWorkflowDriverServiceInstance", si=att_si)
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070045 return att_si
Matteo Scandoloccef5782018-08-13 13:25:17 -070046
47 def process_event(self, event):
48 value = json.loads(event.value)
49 self.log.info("onu.events: received event", value=value)
50
51 if value["status"] == "activated":
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070052 self.log.info("onu.events: activated onu", value=value)
Matteo Scandolo7e22ca12019-03-01 11:57:03 -080053 att_si = self.get_att_si(value)
Matteo Scandolo242c2962018-08-28 16:50:47 -070054 att_si.onu_state = "ENABLED"
Matteo Scandolo7e22ca12019-03-01 11:57:03 -080055 att_si.save_changed_fields(always_update_timestamp=True)
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070056 elif value["status"] == "disabled":
Matteo Scandolo7e22ca12019-03-01 11:57:03 -080057 self.log.info("onu.events: disabled onu, not taking any action", value=value)
58 return
Matteo Scandoloea529092018-09-11 16:36:39 -070059 else:
Matteo Scandolo7e22ca12019-03-01 11:57:03 -080060 self.log.warn("onu.events: Unknown status value: %s" % value["status"], value=value)
61 return