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