blob: 0c9d97891151e3418e7137a75f7808f9efd14025 [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
28 # TODO(smbaker): This is redudant with AttWorkflowDriverWhiteListEntry model policy, though etaining this does provide
29 # a handy way to trigger a full reexamination of the whitelist.
30
Matteo Scandolod6c325a2018-09-04 14:28:23 -070031 whitelist = [x.serial_number.lower() for x in service.whitelist_entries.all()]
Matteo Scandoload0c1752018-08-09 15:47:16 -070032
33 for si in sis:
Matteo Scandolod6c325a2018-09-04 14:28:23 -070034 if si.serial_number.lower() in whitelist and not si.valid == "valid":
Matteo Scandoload0c1752018-08-09 15:47:16 -070035 self.logger.debug("MODEL_POLICY: activating AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
36 si.valid = "valid"
37 si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
Matteo Scandolod6c325a2018-09-04 14:28:23 -070038 if si.serial_number.lower() not in whitelist and not si.valid == "invalid":
Matteo Scandoload0c1752018-08-09 15:47:16 -070039 self.logger.debug(
40 "MODEL_POLICY: disabling AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
41 si.valid = "invalid"
42 si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
43
44
45 def handle_delete(self, si):
46 pass