blob: 8b3ea8d6932988dc64a775619bcf50b5d00122bc [file] [log] [blame]
Andy Bavier561f3e52019-03-15 10:46:05 -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
16import json
17import time
18import os
19import sys
20from xossynchronizer.event_steps.eventstep import EventStep
Scott Bakerc660bd02019-04-02 16:37:07 -070021
22from ..helpers import TtHelpers
Andy Bavier561f3e52019-03-15 10:46:05 -070023
24class SubscriberDhcpEventStep(EventStep):
25 topics = ["dhcp.events"]
26 technology = "kafka"
27
28 def __init__(self, *args, **kwargs):
29 super(SubscriberDhcpEventStep, self).__init__(*args, **kwargs)
30
31 def process_event(self, event):
32 value = json.loads(event.value)
33
34 onu_sn = TtHelpers.get_onu_sn(self.model_accessor, self.log, value)
35 si = TtHelpers.get_si_by_sn(self.model_accessor, self.log, onu_sn)
36
37 if not si:
38 self.log.exception("dhcp.events: Cannot find tt-workflow-driver service instance for this event", kafka_event=value)
39 raise Exception("dhcp.events: Cannot find tt-workflow-driver service instance for this event")
40
41 self.log.info("dhcp.events: Got event for subscriber", event_value=value, onu_sn=onu_sn, si=si)
42
43 si.dhcp_state = value["messageType"]
44 si.ip_address = value["ipAddress"]
45 si.mac_address = value["macAddress"]
46
47 si.save_changed_fields(always_update_timestamp=True)