def transact_block(request, connection): """Emulate jsonrpc.Connection.transact_block without blocking eventlet. """ error = connection.send(request) reply = None if error: return error, reply ovs_poller = poller.Poller() while not error: ovs_poller.immediate_wake() error, reply = connection.recv() if error != errno.EAGAIN: break if (reply and reply.id == request.id and reply.type in (jsonrpc.Message.T_REPLY, jsonrpc.Message.T_ERROR)): break connection.run() connection.wait(ovs_poller) connection.recv_wait(ovs_poller) ovs_poller.block() hub.sleep(0) return error, reply
def start(self): with self.lock: if self.idl is not None: return try: helper = idlutils.get_schema_helper(self.connection, self.schema_name) except Exception: # We may have failed do to set-manager not being called helpers.enable_connection_uri(self.connection) # There is a small window for a race, so retry up to a second @retrying.retry(wait_exponential_multiplier=10, stop_max_delay=1000) def do_get_schema_helper(): return idlutils.get_schema_helper(self.connection, self.schema_name) helper = do_get_schema_helper() helper.register_all() self.idl = idl.Idl(self.connection, helper) idlutils.wait_for_change(self.idl, self.timeout) self.poller = poller.Poller() self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()
def start(self, plugin): # The implementation of this function is same as the base class start() # except that OvnIdl object is created instead of idl.Idl with self.lock: if self.idl is not None: return try: helper = idlutils.get_schema_helper(self.connection, self.schema_name) except Exception: # We may have failed do to set-manager not being called helpers.enable_connection_uri(self.connection) # There is a small window for a race, so retry up to a second @retrying.retry(wait_exponential_multiplier=10, stop_max_delay=1000) def do_get_schema_helper(): return idlutils.get_schema_helper(self.connection, self.schema_name) helper = do_get_schema_helper() helper.register_all() self.idl = OvnIdl(plugin, self.connection, helper) self.idl.set_lock(self.idl.event_lock_name) idlutils.wait_for_change(self.idl, self.timeout) # We would have received the initial dump of all the logical # ports as events by now. Unwatch the create events for # logical ports as it is no longer necessary. self.idl.unwatch_logical_port_create_events() self.poller = poller.Poller() self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()
def conn(): log.info('Connecting to OpenSwitch...') helper = utils.get_schema_helper(self.ovsdb, self.schema_name) helper.register_all() self.idl = idl.Idl(self.ovsdb, helper) utils.wait_for_change(self.idl, self.timeout) self.poller = poller.Poller() self.hdr = handle.OpsHandler(self.idl, self)
def wait_for_change(_idl, timeout, seqno=None): if seqno is None: seqno = _idl.change_seqno stop = time.time() + timeout while _idl.change_seqno == seqno and not _idl.run(): ovs_poller = poller.Poller() _idl.wait(ovs_poller) ovs_poller.timer_wait(timeout * 1000) ovs_poller.block() if time.time() > stop: raise Exception(_("Timeout"))
def start(self): with self.lock: if self.idl is not None: return self.idl = idl.Idl(self.connection, self._schema_helper) idlutils.wait_for_change(self.idl, self.timeout) self.poller = poller.Poller() self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()
def establish_connection(self, table_name_list=None): self._schema_filter = table_name_list with self.lock: if self.idl is not None: return self.idl = self.idl_factory() idlutils.wait_for_change(self.idl, self.timeout) self.poller = poller.Poller() self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()
def start(self): """Start the connection.""" with self.lock: if self.thread is not None: return False if not self.idl.has_ever_connected(): idlutils.wait_for_change(self.idl, self.timeout) try: self.idl.post_connect() except AttributeError: # An ovs.db.Idl class has no post_connect pass self.poller = poller.Poller() self._is_running = True self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()
def start(self, table_name_list=None): """ :param table_name_list: A list of table names for schema_helper to register. When this parameter is given, schema_helper will only register tables which name are in list. Otherwise, schema_helper will register all tables for given schema_name as default. """ self._schema_filter = table_name_list with self.lock: if self.idl is not None: return self.idl = self.idl_factory() idlutils.wait_for_change(self.idl, self.timeout) self.poller = poller.Poller() self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()
def start(self, table_name_list=None): """ :param table_name_list: A list of table names for schema_helper to register. When this parameter is given, schema_helper will only register tables which name are in list. Otherwise, schema_helper will register all tables for given schema_name as default. """ with self.lock: if self.idl is not None: return try: helper = idlutils.get_schema_helper(self.connection, self.schema_name) except Exception: # We may have failed do to set-manager not being called helpers.enable_connection_uri(self.connection, set_timeout=True) # There is a small window for a race, so retry up to a second @retrying.retry(wait_exponential_multiplier=10, stop_max_delay=1000) def do_get_schema_helper(): return idlutils.get_schema_helper(self.connection, self.schema_name) helper = do_get_schema_helper() if table_name_list is None: helper.register_all() else: for table_name in table_name_list: helper.register_table(table_name) self.idl = self.idl_class(self.connection, helper) idlutils.wait_for_change(self.idl, self.timeout) self.poller = poller.Poller() self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()
def run(_idl, q, ev): print("running") last_time = time.time() while True: p = poller.Poller() _idl.wait(p) p.fd_wait(q.alert_fileno, poller.POLLIN) p.block() now = time.time() stat = _idl.run() print(now - last_time, "CHANGED" if stat else "NO CHANGE") last_time = now # Notify client that we have connected and received the initial db if not ev.ready() and stat: print("SENDING EVENT") ev.send(True) try: # For demo, a txn is one cmd. txn obj would just loop over multiple c = q.get_nowait() c.run() status = c.txn.commit() print("STATUS %d %s" % (c.val, status)) if status is c.txn.INCOMPLETE: # still have work to do, put it back on the queue print("Putting back", c.val) q.put(c) elif status is c.txn.TRY_AGAIN: # Row changed and failed verify(), reset and try again c.reset() q.put(c) except eventlet.queue.Empty: print("EMPTY") pass except Exception as ex: print("NOOOOOO!", ex) raise
def start(self, driver, table_name_list=None): # The implementation of this function is same as the base class start() # except that OvnIdl object is created instead of idl.Idl and the # enable_connection_uri() helper isn't called (since ovs-vsctl won't # exist on the controller node when using the reference architecture). with self.lock: if self.idl is not None: return try: helper = idlutils.get_schema_helper(self.connection, self.schema_name) except Exception: # There is a small window for a race, so retry up to a second @tenacity.retry( wait=tenacity.wait_exponential(multiplier=0.01), stop=tenacity.stop_after_delay(1), reraise=True) def do_get_schema_helper(): return idlutils.get_schema_helper(self.connection, self.schema_name) helper = do_get_schema_helper() if table_name_list is None: helper.register_all() else: for table_name in table_name_list: helper.register_table(table_name) idl_cls = self.get_ovn_idl_cls() self.idl = idl_cls(driver, self.connection, helper) self.idl.set_lock(self.idl.event_lock_name) idlutils.wait_for_change(self.idl, self.timeout) self.idl.post_initialize(driver) self.poller = poller.Poller() self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()
def start(self, driver, table_name_list=None): # The implementation of this function is same as the base class start() # except that OvnIdl object is created instead of idl.Idl with self.lock: if self.idl is not None: return try: helper = idlutils.get_schema_helper(self.connection, self.schema_name) except Exception: # We may have failed do to set-manager not being called helpers.enable_connection_uri(self.connection) # There is a small window for a race, so retry up to a second @retrying.retry(wait_exponential_multiplier=10, stop_max_delay=1000) def do_get_schema_helper(): return idlutils.get_schema_helper(self.connection, self.schema_name) helper = do_get_schema_helper() if table_name_list is None: helper.register_all() else: for table_name in table_name_list: helper.register_table(table_name) idl_cls = self.get_ovn_idl_cls() self.idl = idl_cls(driver, self.connection, helper) self.idl.set_lock(self.idl.event_lock_name) idlutils.wait_for_change(self.idl, self.timeout) self.idl.post_initialize(driver) self.poller = poller.Poller() self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()
def start(self, driver, table_name_list=None): # The implementation of this function is same as the base class start() # except that OvnIdl object is created instead of idl.Idl. with self.lock: if self.idl is not None: return helper = self.get_schema_helper() if table_name_list is None: helper.register_all() else: for table_name in table_name_list: helper.register_table(table_name) idl_cls = self.get_ovn_idl_cls() self.idl = idl_cls(driver, self.connection, helper) self.idl.set_lock(self.idl.event_lock_name) idlutils.wait_for_change(self.idl, self.timeout) self.idl.post_initialize(driver) self.poller = poller.Poller() self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start()