def __init__(self, sources=None, db_provider='sqlite3', db_spec=':memory:', debug=False, log=False, auto_netns=False): self.ctime = self.gctime = time.time() self.schema = None self.config = {} self.log = Log(log_id=id(self)) self.readonly = ReadOnly(self) self._auto_netns = auto_netns self._db = None self._dbm_thread = None self._dbm_ready = threading.Event() self._dbm_shutdown = threading.Event() self._global_lock = threading.Lock() self._event_map = None self._event_queue = EventQueue(maxsize=100) # if log: self.log(log) # # fix sources prime if sources is None: sources = [{'target': 'localhost', 'kind': 'local', 'nlm_generator': 1}, {'target': 'localhost/netns', 'kind': 'nsmanager'}] elif not isinstance(sources, (list, tuple)): raise ValueError('sources format not supported') self.sources = SourcesView(self) self._nl = sources self._db_provider = db_provider self._db_spec = db_spec self._db_rtnl_log = debug atexit.register(self.close) self._dbm_ready.clear() self._dbm_autoload = set() self._dbm_thread = threading.Thread(target=self.__dbm__, name='NDB main loop') self._dbm_thread.setDaemon(True) self._dbm_thread.start() self._dbm_ready.wait() for event in tuple(self._dbm_autoload): event.wait() self._dbm_autoload = None self.interfaces = View(self, 'interfaces') self.addresses = View(self, 'addresses') self.routes = View(self, 'routes') self.neighbours = View(self, 'neighbours') self.rules = View(self, 'rules') self.netns = View(self, 'netns', default_target='localhost/netns') self.query = Query(self.schema)
def __init__(self, sources=None, db_provider='sqlite3', db_spec=':memory:', rtnl_log=False, debug=False): self.ctime = self.gctime = time.time() self.schema = None self.config = {} self.debug = Debug() self._db = None self._dbm_thread = None self._dbm_ready = threading.Event() self._dbm_shutdown = threading.Event() self._global_lock = threading.Lock() self._event_map = None self._event_queue = queue.Queue(maxsize=100) # if debug: self.debug(debug) # # fix sources prime if sources is None: sources = [{'target': 'localhost', 'kind': 'local', 'nlm_generator': 1}] elif not isinstance(sources, (list, tuple)): raise ValueError('sources format not supported') self.sources = SourcesView(self) self._nl = sources self._db_provider = db_provider self._db_spec = db_spec self._db_rtnl_log = rtnl_log atexit.register(self.close) self._rtnl_objects = set() self._dbm_ready.clear() self._dbm_thread = threading.Thread(target=self.__dbm__, name='NDB main loop') self._dbm_thread.setDaemon(True) self._dbm_thread.start() self._dbm_ready.wait() self.interfaces = View(self, 'interfaces') self.addresses = View(self, 'addresses') self.routes = View(self, 'routes') self.neighbours = View(self, 'neighbours') self.query = Query(self.schema)
def __init__(self, sources=None, db_provider='sqlite3', db_spec=':memory:', rtnl_log=False): self.ctime = self.gctime = time.time() self.schema = None self._debug = None self._db = None self._dbm_thread = None self._dbm_ready = threading.Event() self._global_lock = threading.Lock() self._event_map = None self._event_queue = queue.Queue(maxsize=100) # # fix sources prime if sources is None: self._nl = {'localhost': {'class': IPRoute}} elif isinstance(sources, NetlinkMixin): self._nl = {'localhost': sources} elif isinstance(sources, dict): self._nl = sources self.sources = {} self._db_provider = db_provider self._db_spec = db_spec self._db_rtnl_log = rtnl_log atexit.register(self.close) self._rtnl_objects = set() self._dbm_ready.clear() self._dbm_thread = threading.Thread(target=self.__dbm__, name='NDB main loop') self._dbm_thread.start() self._dbm_ready.wait() self.interfaces = Factory(self, 'interfaces') self.addresses = Factory(self, 'addresses') self.routes = Factory(self, 'routes') self.neighbours = Factory(self, 'neighbours') self.vlans = Factory(self, 'vlan') self.bridges = Factory(self, 'bridge') self.query = Query(self.schema)
def __init__(self, sources=None, db_provider='sqlite3', db_spec=':memory:', rtnl_debug=False, log=False, auto_netns=False, libc=None): self.ctime = self.gctime = time.time() self.schema = None self.config = {} self.libc = libc or ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) self.log = Log(log_id=id(self)) self.readonly = ReadOnly(self) self._auto_netns = auto_netns self._db = None self._dbm_thread = None self._dbm_ready = threading.Event() self._dbm_shutdown = threading.Event() self._global_lock = threading.Lock() self._event_map = None self._event_queue = EventQueue(maxsize=100) # if log: if isinstance(log, basestring): self.log(log) elif isinstance(log, (tuple, list)): self.log(*log) elif isinstance(log, dict): self.log(**log) else: raise TypeError('wrong log spec format') # # fix sources prime if sources is None: sources = [{'target': 'localhost', 'kind': 'local', 'nlm_generator': 1}] if sys.platform.startswith('linux'): sources.append({'target': 'nsmanager', 'kind': 'nsmanager'}) elif not isinstance(sources, (list, tuple)): raise ValueError('sources format not supported') self.sources = SourcesView(self) self._nl = sources self._db_provider = db_provider self._db_spec = db_spec self._db_rtnl_log = rtnl_debug atexit.register(self.close) self._dbm_ready.clear() self._dbm_autoload = set() self._dbm_thread = threading.Thread(target=self.__dbm__, name='NDB main loop') self._dbm_thread.setDaemon(True) self._dbm_thread.start() self._dbm_ready.wait() for event in tuple(self._dbm_autoload): event.wait() self._dbm_autoload = None self.interfaces = View(self, 'interfaces') self.addresses = View(self, 'addresses') self.routes = View(self, 'routes') self.neighbours = View(self, 'neighbours') self.rules = View(self, 'rules') self.netns = View(self, 'netns', default_target='nsmanager') self.vlans = View(self, 'vlans') self.query = Query(self.schema)