• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python common.uifname函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyroute2.common.uifname函数的典型用法代码示例。如果您正苦于以下问题:Python uifname函数的具体用法?Python uifname怎么用?Python uifname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了uifname函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_create_peer_attrs

    def test_create_peer_attrs(self):
        foo = str(uuid4())
        bar = str(uuid4())
        ifA = uifname()
        ifB = uifname()
        netnsmod.create(foo)
        netnsmod.create(bar)

        with IPDB(nl=NetNS(foo)) as ip:
            ip.create(ifname=ifA,
                      kind='veth',
                      peer={'ifname': ifB,
                            'net_ns_fd': bar}).commit()
            assert ifA in ip.interfaces.keys()
            assert ifB not in ip.interfaces.keys()

        with IPDB(nl=NetNS(bar)) as ip:
            assert ifA not in ip.interfaces.keys()
            assert ifB in ip.interfaces.keys()
            ip.interfaces[ifB].remove().commit()
            assert ifA not in ip.interfaces.keys()
            assert ifB not in ip.interfaces.keys()

        with IPDB(nl=NetNS(foo)) as ip:
            assert ifA not in ip.interfaces.keys()
            assert ifB not in ip.interfaces.keys()

        netnsmod.remove(foo)
        netnsmod.remove(bar)
开发者ID:craneworks,项目名称:pyroute2,代码行数:29,代码来源:test_netns.py


示例2: test_veth_simple

    def test_veth_simple(self):
        ifname = uifname()
        peername = uifname()

        (self
         .ndb
         .interfaces
         .create(ifname=ifname, peer=peername, kind='veth')
         .commit())

        iflink = self.ndb.interfaces[ifname]['link']
        plink = self.ndb.interfaces[peername]['link']

        assert iflink == self.ndb.interfaces[peername]['index']
        assert plink == self.ndb.interfaces[ifname]['index']
        assert grep('%s ip link show' % self.ssh, pattern=ifname)
        assert grep('%s ip link show' % self.ssh, pattern=peername)

        (self
         .ndb
         .interfaces[ifname]
         .remove()
         .commit())

        assert not grep('%s ip link show' % self.ssh, pattern=ifname)
        assert not grep('%s ip link show' % self.ssh, pattern=peername)
开发者ID:svinota,项目名称:pyroute2,代码行数:26,代码来源:test_ndb.py


示例3: test_move_ns_fd

    def test_move_ns_fd(self):
        foo = str(uuid4())
        bar = str(uuid4())
        ifA = uifname()
        ifB = uifname()
        netnsmod.create(foo)
        netnsmod.create(bar)

        with IPDB(nl=NetNS(foo)) as ip:
            ip.create(ifname=ifA, kind='veth', peer=ifB).commit()
            assert ifA in ip.interfaces.keys()
            assert ifB in ip.interfaces.keys()
            with ip.interfaces[ifB] as intf:
                intf.net_ns_fd = bar
            assert ifA in ip.interfaces.keys()
            assert ifB not in ip.interfaces.keys()

        with IPDB(nl=NetNS(bar)) as ip:
            assert ifA not in ip.interfaces.keys()
            assert ifB in ip.interfaces.keys()
            ip.interfaces[ifB].remove().commit()
            assert ifA not in ip.interfaces.keys()
            assert ifB not in ip.interfaces.keys()

        with IPDB(nl=NetNS(foo)) as ip:
            assert ifA not in ip.interfaces.keys()
            assert ifB not in ip.interfaces.keys()

        netnsmod.remove(foo)
        netnsmod.remove(bar)
开发者ID:craneworks,项目名称:pyroute2,代码行数:30,代码来源:test_netns.py


示例4: setup

    def setup(self):
        require_user('root')
        require_executable('busybox')
        self.ip = IPDB()
        # create internal network
        self.if1 = uifname()
        self.if2 = uifname()
        self.ip.create(kind='veth', ifname=self.if1, peer=self.if2).commit()
        # set interfaces up
        with self.ip.interfaces[self.if1] as i:
            i.add_ip('172.16.101.1/24')
            i.up()

        with self.ip.interfaces[self.if2] as i:
            i.up()
        # prepare configuration for udhcpd
        with open('udhcpd.conf.in', 'r') as conf_in:
            with open('udhcpd.conf', 'w') as conf_out:
                conf_out.write('interface %s\n' % self.if1)
                conf_out.write(conf_in.read())
        # run busybox dhcp server on $if1
        with open(os.devnull, 'w') as fnull:
            subprocess.check_call(['busybox', 'udhcpd', 'udhcpd.conf'],
                                  stdout=fnull,
                                  stderr=fnull)
开发者ID:celebdor,项目名称:pyroute2,代码行数:25,代码来源:test_dhcp.py


示例5: test_create

    def test_create(self):
        require_user('root')

        nsid = str(uuid4())
        ipdb_main = IPDB()
        ipdb_test = IPDB(nl=NetNS(nsid))
        if1 = uifname()
        if2 = uifname()

        # create VETH pair
        ipdb_main.create(ifname=if1, kind='veth', peer=if2).commit()

        # move the peer to netns
        with ipdb_main.interfaces[if2] as veth:
            veth.net_ns_fd = nsid

        # assign addresses
        with ipdb_main.interfaces[if1] as veth:
            veth.add_ip('172.16.200.1/24')
            veth.up()

        with ipdb_test.interfaces[if2] as veth:
            veth.add_ip('172.16.200.2/24')
            veth.up()

        # ping peer
        try:
            with open('/dev/null', 'w') as fnull:
                subprocess.check_call(['ping', '-c', '1', '172.16.200.2'],
                                      stdout=fnull, stderr=fnull)
            ret_ping = True
        except Exception:
            ret_ping = False

        # check ARP
        time.sleep(0.5)
        ret_arp = '172.16.200.1' in list(ipdb_test.interfaces[if2].neighbours)
        # ret_arp = list(ipdb_test.interfaces.v0p1.neighbours)

        # cleanup
        ipdb_main.interfaces[if1].remove().commit()
        ipdb_main.release()
        ipdb_test.release()
        netnsmod.remove(nsid)

        assert ret_ping
        assert ret_arp
        assert nsid not in netnsmod.listnetns()
开发者ID:0xD3ADB33F,项目名称:pyroute2,代码行数:48,代码来源:test_netns.py


示例6: _create

 def _create(self, kind, **kwarg):
     name = uifname()
     self.ip.link('add', ifname=name, kind=kind, **kwarg)
     devs = self.ip.link_lookup(ifname=name)
     assert devs
     self.ifaces.extend(devs)
     return (name, devs[0])
开发者ID:celebdor,项目名称:pyroute2,代码行数:7,代码来源:test_ipr.py


示例7: test_commit_barrier

    def test_commit_barrier(self):
        require_user("root")

        ifname = uifname()

        # barrier 0
        try:
            ip = IPDB()
            config.commit_barrier = 0
            ts1 = time.time()
            ip.create(ifname=ifname, kind="dummy").commit()
            ts2 = time.time()
            assert 0 < (ts2 - ts1) < 1
        except:
            raise
        finally:
            config.commit_barrier = 0.2
            ip.interfaces[ifname].remove().commit()
            ip.release()

        # barrier 5
        try:
            ip = IPDB()
            config.commit_barrier = 5
            ts1 = time.time()
            ip.create(ifname=ifname, kind="dummy").commit()
            ts2 = time.time()
            assert 5 < (ts2 - ts1) < 6
        except:
            raise
        finally:
            config.commit_barrier = 0.2
            ip.interfaces[ifname].remove().commit()
            ip.release()
开发者ID:abn,项目名称:pyroute2,代码行数:34,代码来源:test_ipdb.py


示例8: setup

 def setup(self):
     self.ifname = uifname()
     self.ip = IPDB(mode="direct")
     try:
         self.ip.create(ifname=self.ifname, kind="dummy")
     except:
         pass
开发者ID:abn,项目名称:pyroute2,代码行数:7,代码来源:test_ipdb.py


示例9: test_move_ns_pid

    def test_move_ns_pid(self):
        foo = str(uuid4())
        bar = str(uuid4())
        ifA = uifname()
        netnsmod.create(foo)
        netnsmod.create(bar)

        ns_foo = IPDB(nl=NetNS(foo))
        ns_bar = IPDB(nl=NetNS(bar))

        try:
            ns_foo.create(ifname=ifA, kind='dummy').commit()
            with ns_foo.interfaces[ifA] as iface:
                iface.net_ns_pid = ns_bar.nl.server.pid

            assert ifA in ns_bar.interfaces.keys()
            assert ifA not in ns_foo.interfaces.keys()

            with ns_bar.interfaces[ifA] as iface:
                iface.net_ns_pid = ns_foo.nl.server.pid

            assert ifA not in ns_bar.interfaces.keys()
            assert ifA in ns_foo.interfaces.keys()

        finally:
            ns_foo.release()
            ns_bar.release()
            netnsmod.remove(foo)
            netnsmod.remove(bar)
开发者ID:craneworks,项目名称:pyroute2,代码行数:29,代码来源:test_netns.py


示例10: test_basic

    def test_basic(self):
        ifname = uifname()
        ifaddr1 = self.ifaddr()
        ifaddr2 = self.ifaddr()
        ifaddr3 = self.ifaddr()

        (self
         .ndb
         .interfaces
         .create(target=self.netns, ifname=ifname, kind='dummy')
         .ipaddr
         .create(address=ifaddr1, prefixlen=24)
         .create(address=ifaddr2, prefixlen=24)
         .create(address=ifaddr3, prefixlen=24)
         .commit())

        with NDB(sources=[{'target': 'localhost',
                           'netns': self.netns,
                           'kind': 'netns'}]) as ndb:
            if_idx = ndb.interfaces[ifname]['index']
            addr1_idx = ndb.addresses['%s/24' % ifaddr1]['index']
            addr2_idx = ndb.addresses['%s/24' % ifaddr2]['index']
            addr3_idx = ndb.addresses['%s/24' % ifaddr3]['index']

        assert if_idx == addr1_idx == addr2_idx == addr3_idx
开发者ID:svinota,项目名称:pyroute2,代码行数:25,代码来源:test_ndb.py


示例11: test_move

 def test_move(self):
     ifname = uifname()
     ifaddr = self.ifaddr()
     # create the interfaces
     (self
      .ndb
      .interfaces
      .create(ifname=ifname, kind='dummy')
      .commit())
     # move it to a netns
     (self
      .ndb
      .interfaces[ifname]
      .set('net_ns_fd', self.netns)
      .commit())
     # setup the interface only when it is moved
     (self
      .ndb
      .interfaces
      .wait(target=self.netns, ifname=ifname)
      .set('state', 'up')
      .set('address', '00:11:22:33:44:55')
      .ipaddr
      .create(address=ifaddr, prefixlen=24)
      .commit())
     self._assert_test_view(ifname, ifaddr)
开发者ID:svinota,项目名称:pyroute2,代码行数:26,代码来源:test_ndb.py


示例12: test_create

 def test_create(self):
     require_user("root")
     ifname = uifname()
     assert ifname not in self.ip.interfaces
     self.ip.create(ifname=ifname, kind="dummy")
     assert ifname in self.ip.interfaces
     self.ip.interfaces[ifname].remove()
     assert ifname not in self.ip.interfaces
开发者ID:abn,项目名称:pyroute2,代码行数:8,代码来源:test_ipdb.py


示例13: test_simple_deps

    def test_simple_deps(self):

        # register NDB handler to wait for the interface
        self.if_simple = uifname()

        ifaddr = self.ifaddr()
        router = self.ifaddr()
        dst = str(self.ipnets[1].network)

        #
        # simple dummy interface with one address and
        # one dependent route
        #
        (self
         .interfaces
         .append(self
                 .ndb
                 .interfaces
                 .create(ifname=self.if_simple, kind='dummy')
                 .set('state', 'up')
                 .commit()['index']))
        (self
         .ndb
         .addresses
         .create(address=ifaddr,
                 prefixlen=24,
                 index=self.interfaces[-1])
         .commit())

        (self
         .ndb
         .routes
         .create(dst=dst, dst_len=24, gateway=router)
         .commit())

        iface = self.ndb.interfaces[self.if_simple]
        # check everything is in place
        assert grep('%s ip link show' % self.ssh, pattern=self.if_simple)
        assert grep('%s ip route show' % self.ssh, pattern=self.if_simple)
        assert grep('%s ip route show' % self.ssh,
                    pattern='%s.*%s' % (dst, router))

        # remove the interface
        iface.remove()
        iface.commit()

        # check there is no interface, no route
        assert not grep('%s ip link show' % self.ssh, pattern=self.if_simple)
        assert not grep('%s ip route show' % self.ssh, pattern=self.if_simple)
        assert not grep('%s ip route show' % self.ssh,
                        pattern='%s.*%s' % (dst, router))

        # revert the changes using the implicit last_save
        iface.rollback()
        assert grep('%s ip link show' % self.ssh, pattern=self.if_simple)
        assert grep('%s ip route show' % self.ssh, pattern=self.if_simple)
        assert grep('%s ip route show' % self.ssh,
                    pattern='%s.*%s' % (dst, router))
开发者ID:svinota,项目名称:pyroute2,代码行数:58,代码来源:test_ndb.py


示例14: _create_ipvlan

 def _create_ipvlan(self, smode):
     master = uifname()
     ipvlan = uifname()
     # create the master link
     self.ip.link_create(ifname=master, kind='dummy')
     midx = self.ip.link_lookup(ifname=master)[0]
     # check modes
     # maybe move modes dict somewhere else?
     cmode = ifinfmsg.ifinfo.ipvlan_data.modes[smode]
     assert ifinfmsg.ifinfo.ipvlan_data.modes[cmode] == smode
     # create ipvlan
     self.ip.link_create(ifname=ipvlan,
                         kind='ipvlan',
                         link=midx,
                         mode=cmode)
     devs = self.ip.link_lookup(ifname=ipvlan)
     assert devs
     self.ifaces.extend(devs)
开发者ID:FirefighterBlu3,项目名称:pyroute2,代码行数:18,代码来源:test_ipr.py


示例15: test_create_tuntap

    def test_create_tuntap(self):
        # actually this test checks the nlsocket plugin feedback
        # in a pair of remote client/server
        foo = str(uuid4())
        tun = uifname()
        tap = uifname()

        with IPDB(nl=NetNS(foo)) as ip:
            ip.create(ifname=tun, kind='tuntap', mode='tun').commit()
            ip.create(ifname=tap, kind='tuntap', mode='tap').commit()
            assert tun in ip.interfaces.keys()
            assert tap in ip.interfaces.keys()
            ip.interfaces[tun].remove().commit()
            ip.interfaces[tap].remove().commit()
            assert tun not in ip.interfaces.keys()
            assert tap not in ip.interfaces.keys()

        netnsmod.remove(foo)
开发者ID:GateprotectGmbH,项目名称:pyroute2,代码行数:18,代码来源:test_netns.py


示例16: test_fail

    def test_fail(self):

        ifname = uifname()
        kind = uifname()

        ifobj = (self
                 .ndb
                 .interfaces
                 .add(ifname=ifname, kind=kind))

        save = dict(ifobj)

        try:
            ifobj.commit()
        except NetlinkError as e:
            assert e.code == 95  # Operation not supported

        assert save == dict(ifobj)
        assert ifobj.scope == 'invalid'
开发者ID:celebdor,项目名称:pyroute2,代码行数:19,代码来源:test_ndb.py


示例17: create_interfaces

    def create_interfaces(self):
        # dummy interface
        if_dummy = uifname()
        if_vlan_stag = uifname()
        if_vlan_ctag = uifname()
        if_bridge = uifname()
        if_port = uifname()
        ret = []

        with self.nl_class(**self.nl_kwarg) as ipr:

            ipr.link('add',
                     ifname=if_dummy,
                     kind='dummy')
            ret.append(self.link_wait(if_dummy))

            ipr.link('add',
                     ifname=if_vlan_stag,
                     link=ret[-1],
                     vlan_id=101,
                     vlan_protocol=0x88a8,
                     kind='vlan')
            ret.append(self.link_wait(if_vlan_stag))

            ipr.link('add',
                     ifname=if_vlan_ctag,
                     link=ret[-1],
                     vlan_id=1001,
                     vlan_protocol=0x8100,
                     kind='vlan')
            ret.append(self.link_wait(if_vlan_ctag))

            ipr.link('add',
                     ifname=if_port,
                     kind='dummy')
            ret.append(self.link_wait(if_port))

            ipr.link('add',
                     ifname=if_bridge,
                     kind='bridge')
            ret.append(self.link_wait(if_bridge))
            ipr.link('set', index=ret[-2], master=ret[-1])
            return ret
开发者ID:celebdor,项目名称:pyroute2,代码行数:43,代码来源:test_ndb.py


示例18: create

 def create(self, kind='dummy'):
     require_user('root')
     name = uifname()
     self.ip.link('add', ifname=name, kind=kind)
     idx = None
     while not idx:
         idx = self.ip.link_lookup(ifname=name)
     idx = idx[0]
     self.ifaces.append(idx)
     return (name, idx)
开发者ID:svinota,项目名称:pyroute2,代码行数:10,代码来源:test_ipr.py


示例19: test_rename_plus_ipv6

    def test_rename_plus_ipv6(self):
        require_user('root')

        mtu = 1280  # mtu must be >= 1280 if you plan to use IPv6
        txqlen = 2000
        nsid = str(uuid4())
        ipdb_main = IPDB()
        ipdb_test = IPDB(nl=NetNS(nsid))
        if1 = uifname()
        if2 = uifname()
        if3 = uifname()

        # create
        ipdb_main.create(kind='veth',
                         ifname=if1,
                         peer=if2,
                         mtu=mtu,
                         txqlen=txqlen).commit()

        # move
        with ipdb_main.interfaces[if2] as veth:
            veth.net_ns_fd = nsid

        # set it up
        with ipdb_test.interfaces[if2] as veth:
            veth.add_ip('fdb3:84e5:4ff4:55e4::1/64')
            veth.add_ip('fdff:ffff:ffff:ffc0::1/64')
            veth.mtu = mtu
            veth.txqlen = txqlen
            veth.up()
            veth.ifname = if3

        veth = ipdb_test.interfaces.get(if3, None)
        ipdb_main.release()
        ipdb_test.release()
        netnsmod.remove(nsid)

        # check everything
        assert ('fdb3:84e5:4ff4:55e4::1', 64) in veth.ipaddr
        assert ('fdff:ffff:ffff:ffc0::1', 64) in veth.ipaddr
        assert veth.flags & 1
        assert veth.mtu == mtu
        assert veth.txqlen == txqlen
开发者ID:craneworks,项目名称:pyroute2,代码行数:43,代码来源:test_netns.py


示例20: interface_event

def interface_event():
    with open(os.devnull, 'w') as fnull:
        p0 = uifname()
        add_command = 'ip link add dev %s type dummy' % p0
        del_command = 'ip link del dev %s' % p0
        subprocess.call(add_command.split(),
                        stdout=fnull,
                        stderr=fnull)
        subprocess.call(del_command.split(),
                        stdout=fnull,
                        stderr=fnull)
开发者ID:asifhasnain,项目名称:pyroute2,代码行数:11,代码来源:test_examples.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python common.AddrPool类代码示例发布时间:2022-05-27
下一篇:
Python pyroute2.IPRoute类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap