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


Python common.uifname函数代码示例

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


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


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