blob: 92828f630e47dac2be24aea80b15eb919b9df49b [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
Andy Bavier561f3e52019-03-15 10:46:05 -070017from xossynchronizer.event_steps.eventstep import EventStep
Andy Bavier289d7aa2019-04-25 10:00:28 -070018from helpers import TtHelpers
Scott Bakerc660bd02019-04-02 16:37:07 -070019
Andy Bavier561f3e52019-03-15 10:46:05 -070020
21class SubscriberDhcpEventStep(EventStep):
22 topics = ["dhcp.events"]
23 technology = "kafka"
24
25 def __init__(self, *args, **kwargs):
26 super(SubscriberDhcpEventStep, self).__init__(*args, **kwargs)
27
28 def process_event(self, event):
29 value = json.loads(event.value)
Andy Bavier289d7aa2019-04-25 10:00:28 -070030 self.log.info("dhcp.events: Got event for subscriber", event_value=value)
Andy Bavier561f3e52019-03-15 10:46:05 -070031
Andy Bavier289d7aa2019-04-25 10:00:28 -070032 si = TtHelpers.find_or_create_tt_si(self.model_accessor, self.log, value)
33 self.log.debug("dhcp.events: Updating service instance", si=si)
Andy Bavier561f3e52019-03-15 10:46:05 -070034 si.dhcp_state = value["messageType"]
35 si.ip_address = value["ipAddress"]
36 si.mac_address = value["macAddress"]
Andy Bavier561f3e52019-03-15 10:46:05 -070037 si.save_changed_fields(always_update_timestamp=True)