blob: 58ef32fba9143e51b99722b74a02107c2af7093a [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
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 Baker1b3b37b2017-02-21 22:53:33 -080017import os
18import inspect
19import imp
20import sys
21import threading
22import time
23from syncstep import SyncStep
24from synchronizers.new_base.event_loop import XOSObserver
Sapan Bhatia06de76b2017-08-22 16:53:50 -040025
Matteo Scandolo1879ce72017-05-30 15:45:26 -070026from xosconfig import Config
Sapan Bhatia06de76b2017-08-22 16:53:50 -040027from multistructlog import create_logger
28
29log = create_logger(Config().get('logging'))
Scott Baker1b3b37b2017-02-21 22:53:33 -080030
Matteo Scandolo1879ce72017-05-30 15:45:26 -070031watchers_enabled = Config.get("enable_watchers")
Scott Baker1b3b37b2017-02-21 22:53:33 -080032
Matteo Scandolo1879ce72017-05-30 15:45:26 -070033# NOTE is this used or can be removed?
Scott Baker1b3b37b2017-02-21 22:53:33 -080034if (watchers_enabled):
35 from synchronizers.new_base.watchers import XOSWatcher
36
Scott Baker1b3b37b2017-02-21 22:53:33 -080037class Backend:
38 def run(self):
39 # start model policies thread
Matteo Scandolo1879ce72017-05-30 15:45:26 -070040 policies_dir = Config("model_policies_dir")
Scott Baker1b3b37b2017-02-21 22:53:33 -080041 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 Bhatia06de76b2017-08-22 16:53:50 -040047 log.info("Skipping model policies thread due to no model_policies dir.")
Scott Baker1b3b37b2017-02-21 22:53:33 -080048
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