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 | import os |
| 18 | import inspect |
| 19 | import imp |
| 20 | import sys |
| 21 | import threading |
| 22 | import time |
| 23 | from syncstep import SyncStep |
| 24 | from synchronizers.new_base.event_loop import XOSObserver |
Sapan Bhatia | 06de76b | 2017-08-22 16:53:50 -0400 | [diff] [blame^] | 25 | |
Matteo Scandolo | 1879ce7 | 2017-05-30 15:45:26 -0700 | [diff] [blame] | 26 | from xosconfig import Config |
Sapan Bhatia | 06de76b | 2017-08-22 16:53:50 -0400 | [diff] [blame^] | 27 | from multistructlog import create_logger |
| 28 | |
| 29 | log = create_logger(Config().get('logging')) |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 30 | |
Matteo Scandolo | 1879ce7 | 2017-05-30 15:45:26 -0700 | [diff] [blame] | 31 | watchers_enabled = Config.get("enable_watchers") |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 32 | |
Matteo Scandolo | 1879ce7 | 2017-05-30 15:45:26 -0700 | [diff] [blame] | 33 | # NOTE is this used or can be removed? |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 34 | if (watchers_enabled): |
| 35 | from synchronizers.new_base.watchers import XOSWatcher |
| 36 | |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 37 | class Backend: |
| 38 | def run(self): |
| 39 | # start model policies thread |
Matteo Scandolo | 1879ce7 | 2017-05-30 15:45:26 -0700 | [diff] [blame] | 40 | policies_dir = Config("model_policies_dir") |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 41 | if policies_dir: |
| 42 | from synchronizers.model_policy import run_policy |
| 43 | model_policy_thread = threading.Thread(target=run_policy) |
| 44 | model_policy_thread.start() |
| 45 | else: |
| 46 | model_policy_thread = None |
Sapan Bhatia | 06de76b | 2017-08-22 16:53:50 -0400 | [diff] [blame^] | 47 | log.info("Skipping model policies thread due to no model_policies dir.") |
Scott Baker | 1b3b37b | 2017-02-21 22:53:33 -0800 | [diff] [blame] | 48 | |
| 49 | while True: |
| 50 | try: |
| 51 | time.sleep(1000) |
| 52 | except KeyboardInterrupt: |
| 53 | print "exiting due to keyboard interrupt" |
| 54 | if model_policy_thread: |
| 55 | model_policy_thread._Thread__stop() |
| 56 | sys.exit(1) |
| 57 | |