Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 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 Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 17 | #!/usr/bin/env python |
| 18 | import os |
| 19 | import argparse |
| 20 | import sys |
| 21 | |
| 22 | sys.path.append('/opt/xos') |
| 23 | |
| 24 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings") |
Matteo Scandolo | e3d2f26 | 2018-06-05 17:45:39 -0700 | [diff] [blame^] | 25 | import time |
| 26 | from synchronizers.new_base.modelaccessor import * |
Matteo Scandolo | 1879ce7 | 2017-05-30 15:45:26 -0700 | [diff] [blame] | 27 | from xosconfig import Config |
Sapan Bhatia | 06de76b | 2017-08-22 16:53:50 -0400 | [diff] [blame] | 28 | from multistructlog import create_logger |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 29 | from synchronizers.new_base.backend import Backend |
| 30 | |
Matteo Scandolo | e3d2f26 | 2018-06-05 17:45:39 -0700 | [diff] [blame^] | 31 | log = create_logger(Config().get('logging')) |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 32 | def main(): |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 33 | |
| 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 Bhatia | 06de76b | 2017-08-22 16:53:50 -0400 | [diff] [blame] | 42 | log.info("Exception", e = e) |
| 43 | log.info('Waiting for data model to come up before starting...') |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 44 | 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 Bhatia | da5e444 | 2017-08-27 09:51:13 -0400 | [diff] [blame] | 49 | |
| 50 | log_closure = log.bind(synchronizer_name = Config().get('name')) |
| 51 | backend = Backend(log = log_closure) |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 52 | backend.run() |
| 53 | |
| 54 | if __name__ == '__main__': |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 55 | main() |