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 | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 19 | |
| 20 | class 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 Scandolo | e8c33d6 | 2018-08-16 14:37:24 -0700 | [diff] [blame] | 29 | def get_att_si(self, event): |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 30 | try: |
Scott Baker | 71d2047 | 2019-02-01 12:05:35 -0800 | [diff] [blame^] | 31 | att_si = self.model_accessor.AttWorkflowDriverServiceInstance.objects.get(serial_number=event["serial_number"]) |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 32 | att_si.no_sync = False; |
Matteo Scandolo | e8c33d6 | 2018-08-16 14:37:24 -0700 | [diff] [blame] | 33 | att_si.uni_port_id = event["uni_port_id"] |
| 34 | att_si.of_dpid = event["of_dpid"] |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 35 | 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 Baker | 71d2047 | 2019-02-01 12:05:35 -0800 | [diff] [blame^] | 38 | att_si = self.model_accessor.AttWorkflowDriverServiceInstance( |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 39 | serial_number=event["serial_number"], |
Matteo Scandolo | 53da44c | 2018-08-14 16:04:18 -0700 | [diff] [blame] | 40 | of_dpid=event["of_dpid"], |
Matteo Scandolo | 242c296 | 2018-08-28 16:50:47 -0700 | [diff] [blame] | 41 | uni_port_id=event["uni_port_id"], |
Scott Baker | 71d2047 | 2019-02-01 12:05:35 -0800 | [diff] [blame^] | 42 | owner=self.model_accessor.AttWorkflowDriverService.objects.first() # we assume there is only one AttWorkflowDriverService |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 43 | ) |
| 44 | self.log.debug("onu.events: Created new AttWorkflowDriverServiceInstance", si=att_si) |
Matteo Scandolo | e8c33d6 | 2018-08-16 14:37:24 -0700 | [diff] [blame] | 45 | return att_si |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 46 | |
| 47 | def process_event(self, event): |
| 48 | value = json.loads(event.value) |
| 49 | self.log.info("onu.events: received event", value=value) |
| 50 | |
Matteo Scandolo | e8c33d6 | 2018-08-16 14:37:24 -0700 | [diff] [blame] | 51 | att_si = self.get_att_si(value) |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 52 | if value["status"] == "activated": |
Matteo Scandolo | e8c33d6 | 2018-08-16 14:37:24 -0700 | [diff] [blame] | 53 | self.log.info("onu.events: activated onu", value=value) |
Matteo Scandolo | 242c296 | 2018-08-28 16:50:47 -0700 | [diff] [blame] | 54 | att_si.onu_state = "ENABLED" |
Matteo Scandolo | e8c33d6 | 2018-08-16 14:37:24 -0700 | [diff] [blame] | 55 | elif value["status"] == "disabled": |
| 56 | self.log.info("onu.events: disabled onu", value=value) |
| 57 | att_si.onu_state = "DISABLED" |
Matteo Scandolo | b759715 | 2018-08-17 16:33:50 -0700 | [diff] [blame] | 58 | att_si.authentication_state = "AWAITING" |
Matteo Scandolo | ea52909 | 2018-09-11 16:36:39 -0700 | [diff] [blame] | 59 | else: |
| 60 | self.log.warn("onu.events: Unkown status value: %s" % value["status"], value=value) |
Andy Bavier | 0d631eb | 2018-10-17 18:05:04 -0700 | [diff] [blame] | 61 | att_si.save_changed_fields(always_update_timestamp=True) |
Matteo Scandolo | e8c33d6 | 2018-08-16 14:37:24 -0700 | [diff] [blame] | 62 | |
Matteo Scandolo | ccef578 | 2018-08-13 13:25:17 -0700 | [diff] [blame] | 63 | |