blob: 145c46e2f7edc848c5e24b37fd06dc71738d8c58 [file] [log] [blame]
Zack Williams045b63d2019-01-22 16:30:57 -07001#!/usr/bin/env python
Matteo Scandolod2044a42017-08-07 16:08:28 -07002
3# Copyright 2017-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Scott Baker1b3b37b2017-02-21 22:53:33 -080017import os
Scott Baker1b3b37b2017-02-21 22:53:33 -080018import sys
Matteo Scandoloe3d2f262018-06-05 17:45:39 -070019import time
Zack Williams045b63d2019-01-22 16:30:57 -070020
21sys.path.append("/opt/xos")
22os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
23
24from synchronizers.new_base.backend import Backend
Matteo Scandoloe3d2f262018-06-05 17:45:39 -070025from synchronizers.new_base.modelaccessor import *
Zack Williams045b63d2019-01-22 16:30:57 -070026
Matteo Scandolo1879ce72017-05-30 15:45:26 -070027from xosconfig import Config
Sapan Bhatia06de76b2017-08-22 16:53:50 -040028from multistructlog import create_logger
Zack Williams045b63d2019-01-22 16:30:57 -070029log = create_logger(Config().get("logging"))
Scott Baker1b3b37b2017-02-21 22:53:33 -080030
Zack Williams045b63d2019-01-22 16:30:57 -070031
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:
Zack Williams045b63d2019-01-22 16:30:57 -070038 _i = Instance.objects.first()
39 _n = NetworkTemplate.objects.first()
Scott Baker1b3b37b2017-02-21 22:53:33 -080040 models_active = True
Zack Williams045b63d2019-01-22 16:30:57 -070041 except Exception as e:
42 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
Zack Williams045b63d2019-01-22 16:30:57 -070047 if wait:
48 time.sleep(
49 60
50 ) # Safety factor, seeing that we stumbled waiting for the data model to come up.
Zack Williamsee725772018-12-10 14:37:20 -070051
Zack Williams045b63d2019-01-22 16:30:57 -070052 log_closure = log.bind(synchronizer_name=Config().get("name"))
53 backend = Backend(log=log_closure)
Scott Baker1b3b37b2017-02-21 22:53:33 -080054 backend.run()
55
Zack Williams045b63d2019-01-22 16:30:57 -070056
57if __name__ == "__main__":
Scott Baker1b3b37b2017-02-21 22:53:33 -080058 main()