def __init__(self, *argv, **kwarg): kwarg['iclass'] = ifinfmsg.af_spec_bridge.vlan_info if 'auth_managers' not in kwarg or kwarg['auth_managers'] is None: kwarg['auth_managers'] = [] log = argv[0].ndb.log.channel('vlan auth') kwarg['auth_managers'].append(AuthManager({'obj:modify': False}, log)) super(Vlan, self).__init__(*argv, **kwarg)
def __init__(self, view, key, iclass, ctxid=None, load=True, master=None, check=True, auth_managers=None): self.view = view self.ndb = view.ndb self.sources = view.ndb.sources self.master = master self.ctxid = ctxid self.schema = view.ndb.schema self.changed = set() self.iclass = iclass self.utable = self.utable or self.table self.errors = [] self.atime = time.time() self.log = self.ndb.log.channel('rtnl_object') self.log.debug('init') if auth_managers is None: auth_managers = [AuthManager(None, self.ndb.log.channel('auth'))] self.auth_managers = auth_managers self.state = State() self.state.set('invalid') self.snapshot_deps = [] self.load_event = threading.Event() self.load_event.set() self.load_debug = False self.lock = threading.Lock() self.kspec = self.schema.compiled[self.table]['idx'] self.knorm = self.schema.compiled[self.table]['norm_idx'] self.spec = self.schema.compiled[self.table]['all_names'] self.names = self.schema.compiled[self.table]['norm_names'] self.last_save = None if self.event_map is None: self.event_map = {} self._apply_script = [] if isinstance(key, dict): self.chain = key.pop('ndb_chain', None) create = key.pop('create', False) else: self.chain = None create = False exists = self.exists(key) ckey = self.complete_key(key) if create: if check & exists: raise KeyError('object exists') for name in key: self[self.iclass.nla2name(name)] = key[name] # FIXME -- merge with complete_key() if 'target' not in self: self.load_value('target', self.view.default_target) else: if not exists: raise KeyError('object does not exists') self.key = ckey if load: if ctxid is None: self.load_sql() else: self.load_sql(table=self.table) self._init_complete = True
def __init__(self, sources=None, db_provider='sqlite3', db_spec=':memory:', rtnl_debug=False, log=False, auto_netns=False, libc=None, messenger=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) self.messenger = messenger if messenger is not None: self._mm_thread = threading.Thread(target=self.__mm__, name='Messenger') self._mm_thread.setDaemon(True) self._mm_thread.start() # 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') am = AuthManager({'obj:list': True, 'obj:read': True, 'obj:modify': True}, self.log.channel('auth')) self.sources = SourcesView(self, auth_managers=[am]) self._call_registry = {} 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 for spec in (('interfaces', 'localhost'), ('addresses', 'localhost'), ('routes', 'localhost'), ('neighbours', 'localhost'), ('rules', 'localhost'), ('netns', 'nsmanager'), ('vlans', 'localhost')): view = View(self, spec[0], default_target=spec[1], auth_managers=[am]) setattr(self, spec[0], view)