blob: bc55f168d747053befaaaeee27a09231669cf7b4 [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
Scott Bakerc2a633d2019-04-01 19:27:41 -070020
Matteo Scandoloccef5782018-08-13 13:25:17 -070021class ONUEventStep(EventStep):
22 topics = ["onu.events"]
23 technology = "kafka"
24
25 max_onu_retry = 50
26
27 def __init__(self, *args, **kwargs):
28 super(ONUEventStep, self).__init__(*args, **kwargs)
29
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070030 def get_att_si(self, event):
Matteo Scandoloccef5782018-08-13 13:25:17 -070031 try:
Scott Bakerc2a633d2019-04-01 19:27:41 -070032 att_si = self.model_accessor.AttWorkflowDriverServiceInstance.objects.get(
Hardik Windlass7959e1f2019-03-30 20:38:02 +053033 serial_number=event["serialNumber"])
Scott Bakerc2a633d2019-04-01 19:27:41 -070034 att_si.no_sync = False
Hardik Windlass7959e1f2019-03-30 20:38:02 +053035 att_si.uni_port_id = long(event["portNumber"])
36 att_si.of_dpid = event["deviceId"]
Matteo Scandoloccef5782018-08-13 13:25:17 -070037 self.log.debug("onu.events: Found existing AttWorkflowDriverServiceInstance", si=att_si)
38 except IndexError:
Scott Bakerc2a633d2019-04-01 19:27:41 -070039 # create an AttWorkflowDriverServiceInstance, the validation will be
40 # triggered in the corresponding sync step
Scott Baker71d20472019-02-01 12:05:35 -080041 att_si = self.model_accessor.AttWorkflowDriverServiceInstance(
Hardik Windlass7959e1f2019-03-30 20:38:02 +053042 serial_number=event["serialNumber"],
43 of_dpid=event["deviceId"],
44 uni_port_id=long(event["portNumber"]),
Scott Bakerc2a633d2019-04-01 19:27:41 -070045 # we assume there is only one AttWorkflowDriverService
46 owner=self.model_accessor.AttWorkflowDriverService.objects.first()
Matteo Scandoloccef5782018-08-13 13:25:17 -070047 )
48 self.log.debug("onu.events: Created new AttWorkflowDriverServiceInstance", si=att_si)
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070049 return att_si
Matteo Scandoloccef5782018-08-13 13:25:17 -070050
51 def process_event(self, event):
52 value = json.loads(event.value)
53 self.log.info("onu.events: received event", value=value)
54
55 if value["status"] == "activated":
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070056 self.log.info("onu.events: activated onu", value=value)
Matteo Scandolo4f041502019-03-01 11:57:03 -080057 att_si = self.get_att_si(value)
Matteo Scandolo242c2962018-08-28 16:50:47 -070058 att_si.onu_state = "ENABLED"
Matteo Scandolo4f041502019-03-01 11:57:03 -080059 att_si.save_changed_fields(always_update_timestamp=True)
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070060 elif value["status"] == "disabled":
Matteo Scandolo4f041502019-03-01 11:57:03 -080061 self.log.info("onu.events: disabled onu, not taking any action", value=value)
62 return
Matteo Scandoloea529092018-09-11 16:36:39 -070063 else:
Matteo Scandolo4f041502019-03-01 11:57:03 -080064 self.log.warn("onu.events: Unknown status value: %s" % value["status"], value=value)
65 return