def monitor_ovsdb(entity_zoo, extra): pyDatalog.Logic(extra['logic']) cmd = [ 'ovsdb-client', 'monitor', 'Interface', 'ofport', 'name', 'external_ids', '--format=json' ] logger.info("start ovsdb-client instance") try: child = subprocess.Popen(cmd, stdout=subprocess.PIPE, preexec_fn=on_parent_exit('SIGTERM')) with extra['lock']: extra['ovsdb-client'] = child logger.info("monitoring the ovsdb") while child.poll() == None: json_str = child.stdout.readline().strip() output = json.loads(json_str) with entity_zoo.lock: for record in output['data']: update_ovsport(record, entity_zoo) except ValueError as err: if json_str != "": logger.warning("cannot parse %s to json object", json_str) else: logger.info('json_str is empty, maybe we should exit') subprocess.Popen.kill(child) return except Exception as err: logger.exception("exit ovsdb-client monitor, err:%s", str(err)) subprocess.Popen.kill(child) return
def run_pkt_controller_instance(): env = os.environ.copy() if extra.has_key('log_dir'): env['TUPLENET_LOGDIR'] = extra['log_dir'] parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = ['{}/pkt_controller/pkt_controller'.format(parent_dir)] try: child = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env, preexec_fn=on_parent_exit('SIGTERM')) logger.info("the pkt_controller is running now") except Exception as err: logger.warning("cannot open %s, err:%s", cmd, err)