blob: d2fdeeb15bebd2f772ed4cd5b8c1c14108087727 [file] [log] [blame]
Matteo Scandoload0c1752018-08-09 15:47:16 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import json
16from synchronizers.new_base.syncstep import SyncStep, model_accessor
17from synchronizers.new_base.modelaccessor import AttWorkflowDriverServiceInstance, AttWorkflowDriverWhiteListEntry
18
19from xosconfig import Config
20from multistructlog import create_logger
21
22log = create_logger(Config().get('logging'))
23
24class SyncAttWorkflowDriverServiceInstance(SyncStep):
25 provides = [AttWorkflowDriverServiceInstance]
26 observes = AttWorkflowDriverServiceInstance
27
28 def validate_in_external_oss(self, si):
29 # This is where you may want to call your OSS Database to verify if this ONU can be activated
30 oss_service = si.owner.leaf_model
31
32 # See if there is a matching entry in the whitelist.
33
34 matching_entries = AttWorkflowDriverWhiteListEntry.objects.filter(owner_id=oss_service.id,
35 serial_number=si.serial_number)
36
37 return len(matching_entries)>0
38
39 def get_suscriber_c_tag(self, serial_number):
40 # If it's up to your OSS to generate c_tags, fetch them here
41 # otherwise XOS will generate one for your subscriber
42 return None
43
44 def sync_record(self, o):
45 log.info("synching AttWorkflowDriverServiceInstance", object=str(o), **o.tologdict())
46
47 if not self.validate_in_external_oss(o):
48 log.error("ONU with serial number %s is not valid in the OSS Database" % o.serial_number)
49 o.valid = "invalid"
50 else:
51 if self.get_suscriber_c_tag(o.serial_number):
52 self.c_tag = self.get_suscriber_c_tag(o.serial_number)
53
54 o.valid = "valid"
55
56 # Set no_sync=True to prevent the syncstep from running again, and set alway_update_timestamp=True to cause
57 # the model_policy to run again.
58 # TODO(smbaker): Revisit this after fixing this issue in the core.
59 o.no_sync = True
60 o.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
61
62 def delete_record(self, o):
63 pass