当前位置: 首页>>代码示例>>Python>>正文


Python transactional.Transactional类代码示例

本文整理汇总了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]
开发者ID:0x90,项目名称:pyroute2,代码行数:60,代码来源:interface.py

示例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
开发者ID:thezeep,项目名称:pyroute2,代码行数:35,代码来源:interface.py

示例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
开发者ID:nazarewk,项目名称:pyroute2,代码行数:27,代码来源:route.py

示例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
开发者ID:FirefighterBlu3,项目名称:pyroute2,代码行数:9,代码来源:route.py

示例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)
开发者ID:celebdor,项目名称:pyroute2,代码行数:57,代码来源:routes.py

示例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')
开发者ID:jazzmes,项目名称:pyroute2,代码行数:13,代码来源:route.py

示例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)
开发者ID:alexliyu,项目名称:ip-white-list-of-firewall,代码行数:15,代码来源:route.py

示例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
开发者ID:celebdor,项目名称:pyroute2,代码行数:7,代码来源:routes.py

示例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
开发者ID:craneworks,项目名称:pyroute2,代码行数:40,代码来源:interface.py

示例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
开发者ID:celebdor,项目名称:pyroute2,代码行数:4,代码来源:rules.py


注:本文中的pyroute2.ipdb.transactional.Transactional类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。