def factory(cls, sock, address, *args, **kwargs): ovs_stream = stream.Stream(sock, None, None) connection = jsonrpc.Connection(ovs_stream) schemas = discover_schemas(connection) if not schemas: return fsm = reconnect.Reconnect(now()) fsm.set_name('%s:%s' % address) fsm.enable(now()) fsm.set_passive(True, now()) fsm.set_max_tries(-1) fsm.connected(now()) session = jsonrpc.Session(fsm, connection) idl = Idl(session, schemas[0]) system_id = discover_system_id(idl) if not system_id: return None name = cls.instance_name(system_id) ovs_stream.name = name connection.name = name fsm.set_name(name) kwargs = kwargs.copy() kwargs['address'] = address kwargs['idl'] = idl kwargs['name'] = name kwargs['system_id'] = system_id app_mgr = app_manager.AppManager.get_instance() old_app = app_manager.lookup_service_brick(name) old_events = None if old_app: old_events = old_app.events app_mgr.uninstantiate(name) app = app_mgr.instantiate(cls, *args, **kwargs) if old_events: app.events = old_events return app
def factory(cls, sock, address, probe_interval=None, min_backoff=None, max_backoff=None, schema_tables=None, schema_exclude_columns=None, *args, **kwargs): schema_exclude_columns = schema_exclude_columns or {} ovs_stream = stream.Stream(sock, None, None) connection = jsonrpc.Connection(ovs_stream) schemas = discover_schemas(connection) if not schemas: return if schema_tables or schema_exclude_columns: schemas = _filter_schemas(schemas, schema_tables, schema_exclude_columns) fsm = reconnect.Reconnect(now()) fsm.set_name('%s:%s' % address[:2]) fsm.enable(now()) fsm.set_passive(True, now()) fsm.set_max_tries(-1) if probe_interval is not None: fsm.set_probe_interval(probe_interval) if min_backoff is None: min_backoff = fsm.get_min_backoff() if max_backoff is None: max_backoff = fsm.get_max_backoff() if min_backoff and max_backoff: fsm.set_backoff(min_backoff, max_backoff) fsm.connected(now()) session = jsonrpc.Session(fsm, connection) idl = Idl(session, schemas[0]) system_id = discover_system_id(idl) if not system_id: return None name = cls.instance_name(system_id) ovs_stream.name = name connection.name = name fsm.set_name(name) kwargs = kwargs.copy() kwargs['socket'] = sock kwargs['address'] = address kwargs['idl'] = idl kwargs['name'] = name kwargs['system_id'] = system_id app_mgr = app_manager.AppManager.get_instance() old_app = app_manager.lookup_service_brick(name) old_events = None if old_app: old_events = old_app.events app_mgr.uninstantiate(name) app = app_mgr.instantiate(cls, *args, **kwargs) if old_events: app.events = old_events return app