blob: 3559d887a5d9507fc60db46379ecd8cb01d819d6 [file] [log] [blame]
Matteo Scandolob517fb22018-07-29 09:57:17 -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 HippieOSSServiceInstance, model_accessor
18from synchronizers.new_base.policy import Policy
19
20class OSSServicePolicy(Policy):
21 model_name = "HippieOSSService"
22
23 def handle_update(self, service):
24 self.logger.debug("MODEL_POLICY: handle_update for HippieOSSService", oss=service)
25
26 sis = HippieOSSServiceInstance.objects.all()
27
28 whitelist = [x.strip() for x in service.whitelist.split(',')]
29
30 for si in sis:
31 if si.serial_number in whitelist and not si.valid == "valid":
32 self.logger.debug("MODEL_POLICY: activating HippieOSSServiceInstance because of change in the whitelist", si=si)
33 si.valid = "valid"
34 si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
35 if si.serial_number not in whitelist and not si.valid == "invalid":
36 self.logger.debug(
37 "MODEL_POLICY: disabling HippieOSSServiceInstance because of change in the whitelist", si=si)
38 si.valid = "invalid"
39 si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
40
41
42 def handle_delete(self, si):
43 pass