blob: 31c229011a78d833bfdbfb4578574ec529e783f2 [file] [log] [blame]
Matteo Scandolo75298822018-05-22 11:25:42 -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
Matteo Scandolo5a0eed22018-06-01 14:42:43 -070017from synchronizers.new_base.modelaccessor import RCORDSubscriber, ONUDevice, model_accessor
Matteo Scandolo75298822018-05-22 11:25:42 -070018from synchronizers.new_base.policy import Policy
19
20class 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 Scandolo5a0eed22018-06-01 14:42:43 -070025
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 Scandolo75298822018-05-22 11:25:42 -070037 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 Scandolo5a0eed22018-06-01 14:42:43 -070046 return
Matteo Scandolo75298822018-05-22 11:25:42 -070047
48 def handle_delete(self, si):
49 pass