blob: d8ee59364d1d56f8e98efa60b30f74dfb41ecdff [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -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
Scott Baker1b3b37b2017-02-21 22:53:33 -080017#!/usr/bin/env python
18import os
19import argparse
20import sys
21
22sys.path.append('/opt/xos')
23
24os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
Matteo Scandoloe3d2f262018-06-05 17:45:39 -070025import time
26from synchronizers.new_base.modelaccessor import *
Matteo Scandolo1879ce72017-05-30 15:45:26 -070027from xosconfig import Config
Sapan Bhatia06de76b2017-08-22 16:53:50 -040028from multistructlog import create_logger
Scott Baker1b3b37b2017-02-21 22:53:33 -080029from synchronizers.new_base.backend import Backend
30
Matteo Scandoloe3d2f262018-06-05 17:45:39 -070031log = create_logger(Config().get('logging'))
Scott Baker1b3b37b2017-02-21 22:53:33 -080032def main():
Scott Baker1b3b37b2017-02-21 22:53:33 -080033
34 models_active = False
35 wait = False
36 while not models_active:
37 try:
38 _ = Instance.objects.first()
39 _ = NetworkTemplate.objects.first()
40 models_active = True
41 except Exception,e:
Sapan Bhatia06de76b2017-08-22 16:53:50 -040042 log.info("Exception", e = e)
43 log.info('Waiting for data model to come up before starting...')
Scott Baker1b3b37b2017-02-21 22:53:33 -080044 time.sleep(10)
45 wait = True
46
47 if (wait):
48 time.sleep(60) # Safety factor, seeing that we stumbled waiting for the data model to come up.
Sapan Bhatiada5e4442017-08-27 09:51:13 -040049
50 log_closure = log.bind(synchronizer_name = Config().get('name'))
51 backend = Backend(log = log_closure)
Scott Baker1b3b37b2017-02-21 22:53:33 -080052 backend.run()
53
54if __name__ == '__main__':
Scott Baker1b3b37b2017-02-21 22:53:33 -080055 main()