Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import json |
| 16 | from synchronizers.new_base.syncstep import SyncStep, model_accessor |
Matteo Scandolo | 53da44c | 2018-08-14 16:04:18 -0700 | [diff] [blame^] | 17 | from synchronizers.new_base.modelaccessor import AttWorkflowDriverServiceInstance, AttWorkflowDriverWhiteListEntry, ONUDevice |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 18 | |
| 19 | from xosconfig import Config |
| 20 | from multistructlog import create_logger |
| 21 | |
| 22 | log = create_logger(Config().get('logging')) |
| 23 | |
| 24 | class SyncAttWorkflowDriverServiceInstance(SyncStep): |
| 25 | provides = [AttWorkflowDriverServiceInstance] |
| 26 | observes = AttWorkflowDriverServiceInstance |
| 27 | |
Matteo Scandolo | 53da44c | 2018-08-14 16:04:18 -0700 | [diff] [blame^] | 28 | def validate_onu(self, si): |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 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 | |
Matteo Scandolo | 53da44c | 2018-08-14 16:04:18 -0700 | [diff] [blame^] | 37 | # check that it's in the whitelist |
| 38 | if len(matching_entries) == 0: |
| 39 | log.warn("ONU disable as not in whitelist", object=str(si), serial_number=si.serial_number, **si.tologdict()) |
| 40 | return False |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 41 | |
Matteo Scandolo | 53da44c | 2018-08-14 16:04:18 -0700 | [diff] [blame^] | 42 | whitelisted = matching_entries[0] |
| 43 | pon_port = ONUDevice.objects.get().pon_port |
| 44 | if pon_port.port_no != whitelisted.pon_port_id or si.of_dpid != whitelisted.device_id: |
| 45 | log.warn("ONU disable as location don't match", object=str(si), serial_number=si.serial_number, |
| 46 | **si.tologdict()) |
| 47 | return False |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 48 | |
Matteo Scandolo | 53da44c | 2018-08-14 16:04:18 -0700 | [diff] [blame^] | 49 | return True |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 50 | |
Matteo Scandolo | 53da44c | 2018-08-14 16:04:18 -0700 | [diff] [blame^] | 51 | def sync_record(self, si): |
| 52 | log.info("synching AttWorkflowDriverServiceInstance", object=str(si), **si.tologdict()) |
| 53 | |
| 54 | if not self.validate_onu(si): |
| 55 | log.error("ONU with serial number %s is not valid in the OSS Database" % si.serial_number) |
| 56 | si.valid = "invalid" |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 57 | else: |
Matteo Scandolo | 53da44c | 2018-08-14 16:04:18 -0700 | [diff] [blame^] | 58 | si.valid = "valid" |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 59 | |
Matteo Scandolo | 53da44c | 2018-08-14 16:04:18 -0700 | [diff] [blame^] | 60 | si.save() |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 61 | |
| 62 | def delete_record(self, o): |
| 63 | pass |