Matteo Scandolo | 7529882 | 2018-05-22 11:25:42 -0700 | [diff] [blame] | 1 | |
| 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 | |
Matteo Scandolo | 5a0eed2 | 2018-06-01 14:42:43 -0700 | [diff] [blame^] | 17 | from synchronizers.new_base.modelaccessor import RCORDSubscriber, ONUDevice, model_accessor |
Matteo Scandolo | 7529882 | 2018-05-22 11:25:42 -0700 | [diff] [blame] | 18 | from synchronizers.new_base.policy import Policy |
| 19 | |
| 20 | class OSSServiceInstancePolicy(Policy): |
| 21 | model_name = "HippieOSSServiceInstance" |
| 22 | |
| 23 | def handle_update(self, si): |
| 24 | self.logger.debug("MODEL_POLICY: handle_update for HippieOSSServiceInstance %s " % si.id) |
Matteo Scandolo | 5a0eed2 | 2018-06-01 14:42:43 -0700 | [diff] [blame^] | 25 | |
| 26 | if not hasattr(si, 'valid') or si.valid is "awaiting": |
| 27 | self.logger.debug("MODEL_POLICY: skipping handle_update for HippieOSSServiceInstance %s as not validated yet" % si.id) |
| 28 | return |
| 29 | if si.valid == "invalid": |
| 30 | self.logger.debug("MODEL_POLICY: disabling ONUDevice [%s] for HippieOSSServiceInstance %s" % (si.serial_number, si.id)) |
| 31 | onu = ONUDevice.objects.get(serial_number=si.serial_number) |
| 32 | onu.admin_state = "DISABLED" |
| 33 | onu.save(always_update_timestamp=True) |
| 34 | return |
| 35 | if si.valid == "valid": |
| 36 | self.logger.debug("MODEL_POLICY: creating RCORDSubscriber for HippieOSSServiceInstance %s" % si.id) |
Matteo Scandolo | 7529882 | 2018-05-22 11:25:42 -0700 | [diff] [blame] | 37 | subscriber = RCORDSubscriber() |
| 38 | subscriber.onu_device = si.serial_number |
| 39 | subscriber.uni_port_id = si.uni_port_id |
| 40 | |
| 41 | # If the OSS returns a c_tag use that one |
| 42 | if si.c_tag: |
| 43 | subscriber.c_tag = si.c_tag |
| 44 | |
| 45 | subscriber.save() |
Matteo Scandolo | 5a0eed2 | 2018-06-01 14:42:43 -0700 | [diff] [blame^] | 46 | return |
Matteo Scandolo | 7529882 | 2018-05-22 11:25:42 -0700 | [diff] [blame] | 47 | |
| 48 | def handle_delete(self, si): |
| 49 | pass |