def __init__(self, ipdb, mode=None, parent=None, uid=None): ''' Parameters: * ipdb -- ipdb() reference * mode -- transaction mode ''' Transactional.__init__(self, ipdb, mode) self.cleanup = ('header', 'linkinfo', 'protinfo', 'af_spec', 'attrs', 'event', 'map', 'stats', 'stats64', 'change', '__align') self.ingress = None self.egress = None self.nlmsg = None self.errors = [] self.partial = False self._exception = None self._tb = None self._linked_sets.add('ipaddr') self._linked_sets.add('ports') self._linked_sets.add('vlans') self._freeze = None self._delay_add_port = set() self._delay_del_port = set() # 8<----------------------------------- # local setup: direct state is required with self._direct_state: for i in ('change', 'mask'): del self[i] self['ipaddr'] = self.ipdb.init_ipaddr_set() self['ports'] = LinkedSet() self['vlans'] = LinkedSet() self['ipdb_priority'] = 0
def __init__(self, ipdb, mode=None, parent=None, uid=None): ''' Parameters: * ipdb -- ipdb() reference * mode -- transaction mode ''' Transactional.__init__(self, ipdb, mode) self.cleanup = ('header', 'linkinfo', 'af_spec', 'attrs', 'event', 'map', 'stats', 'stats64', '__align') self.ingress = None self.egress = None self.nlmsg = None self._exception = None self._tb = None self._load_event = threading.Event() self._linked_sets.add('ipaddr') self._linked_sets.add('ports') self._freeze = None # 8<----------------------------------- # local setup: direct state is required with self._direct_state: for i in self._fields: self[i] = None for i in ('change', 'mask'): del self[i] self['ipaddr'] = IPaddrSet() self['ports'] = LinkedSet() self['ipdb_priority'] = 0
def device_put(self, msg, skip_slaves=False): # check, if a record exists index = msg.get('index', None) ifname = msg.get_attr('IFLA_IFNAME', None) # scenario #1: no matches for both: new interface # scenario #2: ifname exists, index doesn't: index changed # scenario #3: index exists, ifname doesn't: name changed # scenario #4: both exist: assume simple update and # an optional name change if ((index not in self.interfaces) and (ifname not in self.interfaces)): # scenario #1, new interface if compat.fix_check_link(self.nl, index): return device = \ self.by_index[index] = \ self.interfaces[index] = \ self.interfaces[ifname] = \ self.by_name[ifname] = self.iclass(ipdb=self) elif ((index not in self.interfaces) and (ifname in self.interfaces)): # scenario #2, index change old_index = self.interfaces[ifname]['index'] device = \ self.interfaces[index] = \ self.by_index[index] = self.interfaces[ifname] if old_index in self.interfaces: del self.interfaces[old_index] del self.by_index[old_index] if old_index in self.ipaddr: self.ipaddr[index] = self.ipaddr[old_index] del self.ipaddr[old_index] if old_index in self.neighbors: self.neighbors[index] = self.neighbors[old_index] del self.neighbors[old_index] else: # scenario #3, interface rename # scenario #4, assume rename old_name = self.interfaces[index]['ifname'] if old_name != ifname: # unlink old name del self.interfaces[old_name] del self.by_name[old_name] device = \ self.interfaces[ifname] = \ self.by_name[ifname] = self.interfaces[index] if index not in self.ipaddr: # for interfaces, created by IPDB self.ipaddr[index] = IPaddrSet() if index not in self.neighbors: self.neighbors[index] = LinkedSet() device.load_netlink(msg) if not skip_slaves: self.update_slaves(msg)
def __init__(self, ipdb, mode=None, parent=None, uid=None): ''' Parameters: * ipdb -- ipdb() reference * mode -- transaction mode ''' Transactional.__init__(self, ipdb, mode) self.cleanup = ('header', 'linkinfo', 'af_spec', 'attrs', 'event', 'map', 'stats', 'stats64') self.ingress = None self.egress = None self._exists = False self._flicker = False self._exception = None self._tb = None self._virtual_fields = ('removal', 'flicker', 'state') self._xfields = { 'common': [ifinfmsg.nla2name(i[0]) for i in ifinfmsg.nla_map] } self._xfields['common'].append('index') self._xfields['common'].append('flags') self._xfields['common'].append('mask') self._xfields['common'].append('change') self._xfields['common'].append('kind') self._xfields['common'].append('peer') self._xfields['common'].append('vlan_id') self._xfields['common'].append('bond_mode') brmsg = ifinfmsg.ifinfo.bridge_data self._xfields['common'].extend( [brmsg.nla2name(i[0]) for i in brmsg.nla_map]) bomsg = ifinfmsg.ifinfo.bond_data self._xfields['common'].extend( [bomsg.nla2name(i[0]) for i in bomsg.nla_map]) tuntap = ifinfmsg.ifinfo.tuntap_data self._xfields['common'].extend( [tuntap.nla2name(i[0]) for i in tuntap.nla_map]) for ftype in self._xfields: self._fields += self._xfields[ftype] self._fields.extend(self._virtual_fields) self._load_event = threading.Event() self._linked_sets.add('ipaddr') self._linked_sets.add('ports') self._freeze = None # 8<----------------------------------- # local setup: direct state is required with self._direct_state: self['ipaddr'] = IPaddrSet() self['ports'] = LinkedSet() for i in self._fields: self[i] = None for i in ('state', 'change', 'mask'): del self[i]
def _new(self, msg, skip_master=False): # check, if a record exists index = msg.get('index', None) ifname = msg.get_attr('IFLA_IFNAME', None) device = None cleanup = None # scenario #1: no matches for both: new interface # # scenario #2: ifname exists, index doesn't: # index changed # scenario #3: index exists, ifname doesn't: # name changed # scenario #4: both exist: assume simple update and # an optional name change if (index not in self) and (ifname not in self): # scenario #1, new interface device = \ self[index] = \ self[ifname] = Interface(ipdb=self.ipdb) elif (index not in self) and (ifname in self): # scenario #2, index change old_index = self[ifname]['index'] device = self[index] = self[ifname] if old_index in self: cleanup = old_index if old_index in self.ipdb.ipaddr: self.ipdb.ipaddr[index] = \ self.ipdb.ipaddr[old_index] del self.ipdb.ipaddr[old_index] if old_index in self.ipdb.neighbours: self.ipdb.neighbours[index] = \ self.ipdb.neighbours[old_index] del self.neighbours[old_index] else: # scenario #3, interface rename # scenario #4, assume rename old_name = self[index]['ifname'] if old_name != ifname: # unlink old name cleanup = old_name device = self[ifname] = self[index] if index not in self.ipdb.ipaddr: self.ipdb.ipaddr[index] = IPaddrSet() if index not in self.ipdb.neighbours: self.ipdb.neighbours[index] = LinkedSet() # update port references old_master = device.get('master', None) new_master = msg.get_attr('IFLA_MASTER') if old_master != new_master: if old_master in self: with self[old_master]._direct_state: if index in self[old_master]['ports']: self[old_master].del_port(index) if new_master in self and new_master != index: with self[new_master]._direct_state: self[new_master].add_port(index) if cleanup is not None: del self[cleanup] if skip_master: msg.strip('IFLA_MASTER') device.load_netlink(msg) if new_master is None: with device._direct_state: device['master'] = None