blob: 197e26c8c77b258e82dbcaa49384c31153bb0f94 [file] [log] [blame]
Matteo Scandolo75298822018-05-22 11:25:42 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import json
16from synchronizers.new_base.SyncInstanceUsingAnsible import SyncStep
17from synchronizers.new_base.modelaccessor import HippieOSSServiceInstance
18
19from xosconfig import Config
20from multistructlog import create_logger
21
22log = create_logger(Config().get('logging'))
23
24class SyncOSSServiceInstance(SyncStep):
25 provides = [HippieOSSServiceInstance]
26 observes = HippieOSSServiceInstance
27
28 def validate_in_external_oss(self, serial_number):
29 # This is where you may want to call your OSS Database to verify if this ONU can be activated
30 return True
31
32 def get_suscriber_c_tag(self, serial_number):
33 # If it's up to your OSS to generate c_tags, fetch them here
34 # otherwise XOS will generate one for your subscriber
35 return None
36
37 def sync_record(self, o):
38 log.info("synching HippieOSSServiceInstance", object=str(o), **o.tologdict())
39
40 if not self.validate_in_external_oss(o.serial_number):
41 log.error("ONU with serial number %s is not valid in the OSS Database")
42 return
43
44 if self.get_suscriber_c_tag(o.serial_number):
45 self.c_tag = self.get_suscriber_c_tag(o.serial_number)
46
47 o.valid = True
48
49 # FIXME why without this model_policies won't run the handle_update?
50 o.no_sync = True
51 o.save(always_update_timestamp=True)
52
53 def delete_record(self, o):
54 pass