Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -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 | import json |
| 17 | import time |
| 18 | import os |
| 19 | import sys |
Scott Baker | 71d2047 | 2019-02-01 12:05:35 -0800 | [diff] [blame^] | 20 | from xossynchronizer.event_steps.eventstep import EventStep |
Matteo Scandolo | de8cfa8 | 2018-10-16 13:49:05 -0700 | [diff] [blame] | 21 | from helpers import AttHelpers |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 22 | |
| 23 | class SubscriberDhcpEventStep(EventStep): |
| 24 | topics = ["dhcp.events"] |
| 25 | technology = "kafka" |
| 26 | |
| 27 | def __init__(self, *args, **kwargs): |
| 28 | super(SubscriberDhcpEventStep, self).__init__(*args, **kwargs) |
| 29 | |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 30 | def process_event(self, event): |
| 31 | value = json.loads(event.value) |
| 32 | |
Scott Baker | 71d2047 | 2019-02-01 12:05:35 -0800 | [diff] [blame^] | 33 | onu_sn = AttHelpers.get_onu_sn(self.model_accessor, self.log, value) |
| 34 | si = AttHelpers.get_si_by_sn(self.model_accessor, self.log, onu_sn) |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 35 | |
Matteo Scandolo | de8cfa8 | 2018-10-16 13:49:05 -0700 | [diff] [blame] | 36 | if not si: |
| 37 | self.log.exception("dhcp.events: Cannot find att-workflow-driver service instance for this event", kafka_event=value) |
| 38 | raise Exception("dhcp.events: Cannot find att-workflow-driver service instance for this event") |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 39 | |
Matteo Scandolo | de8cfa8 | 2018-10-16 13:49:05 -0700 | [diff] [blame] | 40 | self.log.info("dhcp.events: Got event for subscriber", event_value=value, onu_sn=onu_sn, si=si) |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 41 | |
Scott Baker | 0b4ad93 | 2018-11-26 15:02:13 -0800 | [diff] [blame] | 42 | si.dhcp_state = value["messageType"] |
| 43 | si.ip_address = value["ipAddress"] |
| 44 | si.mac_address = value["macAddress"] |
Matteo Scandolo | 74f6330 | 2018-11-01 14:05:01 -0700 | [diff] [blame] | 45 | |
Andy Bavier | 0d631eb | 2018-10-17 18:05:04 -0700 | [diff] [blame] | 46 | si.save_changed_fields(always_update_timestamp=True) |