Matteo Scandolo | ceccb1f | 2017-06-05 10:35:44 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | import os |
| 3 | import argparse |
| 4 | import sys |
| 5 | |
| 6 | sys.path.append('/opt/xos') |
| 7 | from xosconfig import Config |
| 8 | |
| 9 | config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/openstack_config.yaml') |
| 10 | Config.init(config_file, 'synchronizer-config-schema.yaml') |
| 11 | |
| 12 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings") |
| 13 | from xos.logger import Logger, logging, logger |
| 14 | import time |
| 15 | |
| 16 | from synchronizers.new_base.modelaccessor import * |
| 17 | from synchronizers.new_base.backend import Backend |
| 18 | from synchronizers.new_base.event_loop import set_driver |
| 19 | |
| 20 | logger = Logger(level=logging.INFO) |
| 21 | |
| 22 | # TODO: These two lines are the only difference between this file and |
| 23 | # new_base/openstack-synchronizer.py. Reconcile these. |
| 24 | # set the driver. |
| 25 | from synchronizers.openstack.driver import OpenStackDriver |
| 26 | set_driver(OpenStackDriver()) |
| 27 | |
| 28 | |
| 29 | def main(): |
| 30 | models_active = False |
| 31 | wait = False |
| 32 | while not models_active: |
| 33 | try: |
| 34 | _ = Instance.objects.first() |
| 35 | _ = NetworkTemplate.objects.first() |
| 36 | models_active = True |
| 37 | except Exception,e: |
| 38 | logger.info(str(e)) |
| 39 | logger.info('Waiting for data model to come up before starting...') |
| 40 | time.sleep(10) |
| 41 | wait = True |
| 42 | |
| 43 | if (wait): |
| 44 | time.sleep(60) # Safety factor, seeing that we stumbled waiting for the data model to come up. |
| 45 | backend = Backend() |
| 46 | backend.run() |
| 47 | |
| 48 | if __name__ == '__main__': |
| 49 | |
| 50 | main() |