blob: f21231ccb0fbf476133f55332e5616b5b13d017c [file] [log] [blame]
Matteo Scandoloccef5782018-08-13 13:25:17 -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
16
17import json
18import time
19import os
20import sys
21from synchronizers.new_base.eventstep import EventStep
Matteo Scandolo242c2962018-08-28 16:50:47 -070022from synchronizers.new_base.modelaccessor import AttWorkflowDriverService, AttWorkflowDriverServiceInstance, model_accessor
Matteo Scandoloccef5782018-08-13 13:25:17 -070023
24class ONUEventStep(EventStep):
25 topics = ["onu.events"]
26 technology = "kafka"
27
28 max_onu_retry = 50
29
30 def __init__(self, *args, **kwargs):
31 super(ONUEventStep, self).__init__(*args, **kwargs)
32
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070033 def get_att_si(self, event):
Matteo Scandoloccef5782018-08-13 13:25:17 -070034 try:
35 att_si = AttWorkflowDriverServiceInstance.objects.get(serial_number=event["serial_number"])
36 att_si.no_sync = False;
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070037 att_si.uni_port_id = event["uni_port_id"]
38 att_si.of_dpid = event["of_dpid"]
Matteo Scandoloccef5782018-08-13 13:25:17 -070039 self.log.debug("onu.events: Found existing AttWorkflowDriverServiceInstance", si=att_si)
40 except IndexError:
41 # create an AttWorkflowDriverServiceInstance, the validation will be triggered in the corresponding sync step
42 att_si = AttWorkflowDriverServiceInstance(
43 serial_number=event["serial_number"],
Matteo Scandolo53da44c2018-08-14 16:04:18 -070044 of_dpid=event["of_dpid"],
Matteo Scandolo242c2962018-08-28 16:50:47 -070045 uni_port_id=event["uni_port_id"],
46 owner=AttWorkflowDriverService.objects.first() # we assume there is only one AttWorkflowDriverService
Matteo Scandoloccef5782018-08-13 13:25:17 -070047 )
48 self.log.debug("onu.events: Created new AttWorkflowDriverServiceInstance", si=att_si)
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070049 return att_si
Matteo Scandoloccef5782018-08-13 13:25:17 -070050
51 def process_event(self, event):
52 value = json.loads(event.value)
53 self.log.info("onu.events: received event", value=value)
54
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070055 att_si = self.get_att_si(value)
Matteo Scandoloccef5782018-08-13 13:25:17 -070056 if value["status"] == "activated":
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070057 self.log.info("onu.events: activated onu", value=value)
Matteo Scandolo242c2962018-08-28 16:50:47 -070058 att_si.onu_state = "ENABLED"
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070059 elif value["status"] == "disabled":
60 self.log.info("onu.events: disabled onu", value=value)
61 att_si.onu_state = "DISABLED"
Matteo Scandolob7597152018-08-17 16:33:50 -070062 att_si.authentication_state = "AWAITING"
Matteo Scandoloe8c33d62018-08-16 14:37:24 -070063 att_si.save(always_update_timestamp=True)
64
Matteo Scandoloccef5782018-08-13 13:25:17 -070065