blob: a256fd6d78494f6990789da79aa22882c86dc15b [file] [log] [blame]
Matteo Scandoload0c1752018-08-09 15:47:16 -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
Scott Baker71d20472019-02-01 12:05:35 -080017from xossynchronizer.event_steps.eventstep import EventStep
Matteo Scandolode8cfa82018-10-16 13:49:05 -070018from helpers import AttHelpers
Matteo Scandoload0c1752018-08-09 15:47:16 -070019
Scott Bakerc2a633d2019-04-01 19:27:41 -070020
Matteo Scandoload0c1752018-08-09 15:47:16 -070021class SubscriberDhcpEventStep(EventStep):
22 topics = ["dhcp.events"]
23 technology = "kafka"
24
25 def __init__(self, *args, **kwargs):
26 super(SubscriberDhcpEventStep, self).__init__(*args, **kwargs)
27
Matteo Scandoload0c1752018-08-09 15:47:16 -070028 def process_event(self, event):
29 value = json.loads(event.value)
Matteo Scandolo59e10fc2019-04-18 14:19:52 -070030 self.log.info("dhcp.events: Got event for subscriber", event_value=value)
Matteo Scandoload0c1752018-08-09 15:47:16 -070031
Matteo Scandolo59e10fc2019-04-18 14:19:52 -070032 si = AttHelpers.find_or_create_att_si(self.model_accessor, self.log, value)
33 self.log.debug("dhcp.events: Updating service instance", si=si)
Scott Baker0b4ad932018-11-26 15:02:13 -080034 si.dhcp_state = value["messageType"]
35 si.ip_address = value["ipAddress"]
36 si.mac_address = value["macAddress"]
Andy Bavier0d631eb2018-10-17 18:05:04 -070037 si.save_changed_fields(always_update_timestamp=True)