本文整理汇总了Python中pyroute2.ipdb.transactional.Transactional类的典型用法代码示例。如果您正苦于以下问题:Python Transactional类的具体用法?Python Transactional怎么用?Python Transactional使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transactional类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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._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')
for data in ('bridge_data',
'bond_data',
'tuntap_data',
'vxlan_data',
'gre_data',
'macvlan_data',
'macvtap_data'):
msg = getattr(ifinfmsg.ifinfo, data)
self._xfields['common'].extend([msg.nla2name(i[0]) for i
in msg.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]
示例2: __init__
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
示例3: __init__
def __init__(self, ipdb, mode=None, parent=None, uid=None):
Transactional.__init__(self, ipdb, mode, parent, uid)
self._load_event = threading.Event()
self._fields = [rtmsg.nla2name(i[0]) for i in rtmsg.nla_map]
self._fields.append('flags')
self._fields.append('src_len')
self._fields.append('dst_len')
self._fields.append('table')
self._fields.append('removal')
self._virtual_fields = ['ipdb_scope', 'ipdb_priority']
def make_set_value(self, key):
def set_value(value):
self[key] = value
return self
return set_value
for key in self._fields + self._virtual_fields:
setattr(self, 'set_%s' % key, make_set_value(self, key))
self._fields.extend(self._virtual_fields)
self.cleanup = ('attrs',
'header',
'event')
with self._direct_state:
for i in self._fields:
self[i] = None
self['metrics'] = Metrics(parent=self)
self['ipdb_priority'] = 0
示例4: __init__
def __init__(self, ipdb, mode=None, parent=None, uid=None):
Transactional.__init__(self, ipdb, mode, parent, uid)
self._load_event = threading.Event()
with self._direct_state:
for i in self._fields:
self[i] = None
self['metrics'] = Metrics(parent=self)
self['multipath'] = NextHopSet()
self['ipdb_priority'] = 0
示例5: __setitem__
def __setitem__(self, key, value):
ret = value
if (key in ('encap', 'metrics')) and isinstance(value, dict):
# transactionals attach as is
if type(value) in (Encap, Metrics):
with self._direct_state:
return Transactional.__setitem__(self, key, value)
# check, if it exists already
ret = Transactional.__getitem__(self, key)
# it doesn't
# (plain dict can be safely discarded)
if (type(ret) == dict) or not ret:
# bake transactionals in place
if key == 'encap':
ret = Encap(parent=self)
elif key == 'metrics':
ret = Metrics(parent=self)
# attach transactional to the route
with self._direct_state:
Transactional.__setitem__(self, key, ret)
# begin() works only if the transactional is attached
if any(value.values()):
if self._mode in ('implicit', 'explicit'):
ret._begin(tid=self.current_tx.uid)
[ret.__setitem__(k, v) for k, v
in value.items() if v is not None]
# corresponding transactional exists
else:
# set fields
for k in ret:
ret[k] = value.get(k, None)
return
elif key == 'multipath':
cur = Transactional.__getitem__(self, key)
if isinstance(cur, NextHopSet):
# load entries
vs = NextHopSet(value)
for key in vs - cur:
cur.add(key)
for key in cur - vs:
cur.remove(key)
else:
# drop any result of `update()`
Transactional.__setitem__(self, key, NextHopSet(value))
return
elif key == 'encap_type' and not isinstance(value, int):
ret = encap_type.get(value, value)
elif key == 'type' and not isinstance(value, int):
ret = rt_type.get(value, value)
elif key == 'proto' and not isinstance(value, int):
ret = rt_proto.get(value, value)
elif key == 'dst' and \
isinstance(value, basestring) and \
value in ('0.0.0.0/0', '::/0'):
ret = 'default'
Transactional.__setitem__(self, key, ret)
示例6: __init__
def __init__(self, ipdb, mode=None):
Transactional.__init__(self, ipdb, mode)
self._exists = False
self._load_event = threading.Event()
self._fields = [rtmsg.nla2name(i[0]) for i in rtmsg.nla_map]
self._fields.append('flags')
self._fields.append('src_len')
self._fields.append('dst_len')
self._fields.append('table')
self._fields.append('removal')
self.cleanup = ('attrs',
'header',
'event')
示例7: __init__
def __init__(self, ipdb, mode=None, parent=None, uid=None):
Transactional.__init__(self, ipdb, mode, parent, uid)
self._exists = False
self._load_event = threading.Event()
self._fields = [rtmsg.nla2name(i[0]) for i in rtmsg.nla_map]
self._fields.append('flags')
self._fields.append('src_len')
self._fields.append('dst_len')
self._fields.append('table')
self._fields.append('removal')
self.cleanup = ('attrs',
'header',
'event')
with self._direct_state:
self['metrics'] = Metrics(parent=self)
示例8: __getitem__
def __getitem__(self, key):
ret = Transactional.__getitem__(self, key)
if (key in ('encap', 'metrics', 'multipath')) and (ret is None):
with self._direct_state:
self[key] = [] if key == 'multipath' else {}
ret = self[key]
return ret
示例9: __init__
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
示例10: __init__
def __init__(self, ipdb, mode=None, parent=None, uid=None):
Transactional.__init__(self, ipdb, mode, parent, uid)
with self._direct_state:
self['ipdb_priority'] = 0