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