blob: f738c3a3d396170ba70abbdd384d49e1f1fe615f [file] [log] [blame]
Matteo Scandoload0c1752018-08-09 15:47:16 -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
17from synchronizers.new_base.modelaccessor import AttWorkflowDriverServiceInstance, model_accessor
18from synchronizers.new_base.policy import Policy
19
20class AttWorkflowDriverServicePolicy(Policy):
21 model_name = "AttWorkflowDriverService"
22
23 def handle_update(self, service):
24 self.logger.debug("MODEL_POLICY: handle_update for AttWorkflowDriverService", oss=service)
25
26 sis = AttWorkflowDriverServiceInstance.objects.all()
27
Matteo Scandoloea529092018-09-11 16:36:39 -070028 # TODO(teone): use the method defined in helpers.py
Matteo Scandoload0c1752018-08-09 15:47:16 -070029
Matteo Scandolod6c325a2018-09-04 14:28:23 -070030 whitelist = [x.serial_number.lower() for x in service.whitelist_entries.all()]
Matteo Scandoload0c1752018-08-09 15:47:16 -070031
32 for si in sis:
Matteo Scandolod6c325a2018-09-04 14:28:23 -070033 if si.serial_number.lower() in whitelist and not si.valid == "valid":
Matteo Scandoload0c1752018-08-09 15:47:16 -070034 self.logger.debug("MODEL_POLICY: activating AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
35 si.valid = "valid"
36 si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
Matteo Scandolod6c325a2018-09-04 14:28:23 -070037 if si.serial_number.lower() not in whitelist and not si.valid == "invalid":
Matteo Scandoload0c1752018-08-09 15:47:16 -070038 self.logger.debug(
39 "MODEL_POLICY: disabling AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
40 si.valid = "invalid"
41 si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
42
43
44 def handle_delete(self, si):
45 pass