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

Python pyroute2.IPDB类代码示例

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

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



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

示例1: test_fail_released

 def test_fail_released(self):
     ip = IPDB()
     ip.release()
     try:
         ip.interfaces.lo.up()
     except RuntimeError:
         pass
开发者ID:0x90,项目名称:pyroute2,代码行数:7,代码来源:test_ipdb.py


示例2: 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


示例3: test_create_gretap

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

        ifL = self.get_ifname()
        ifV = self.get_ifname()
        with self.ip.create(kind='dummy', ifname=ifL) as i:
            i.add_ip('172.16.0.1/24')
            i.up()

        self.ip.create(kind='gretap',
                       ifname=ifV,
                       gre_local='172.16.0.1',
                       gre_ikey=1,
                       gre_okey=2,
                       gre_iflags=0x0020,
                       gre_oflags=0x0020,
                       gre_collect_metadata=True,
                       gre_ttl=16).commit()

        ip2 = IPDB()
        ifdb = ip2.interfaces
        try:
            assert ifdb[ifV].gre_local == '172.16.0.1'
            assert ifdb[ifV].gre_ikey == 1
            assert ifdb[ifV].gre_okey == 2
            assert ifdb[ifV].gre_iflags == 0x0020
            assert ifdb[ifV].gre_oflags == 0x0020
            if kernel_version_ge(4, 3):
                assert ifdb[ifV].gre_collect_metadata
            assert ifdb[ifV].gre_ttl == 16
        except Exception:
            raise
        finally:
            ip2.release()
开发者ID:linzhonghong,项目名称:pyroute2,代码行数:34,代码来源:test_ipdb.py


示例4: __ovs_setup

    def __ovs_setup(self):
        if not self.ovs_client.bridgeExists('cygnet0'):
            self.ovs_client.addBridge('cygnet0')
            self.ovs_client.addPort('cygnet0', self.external_iface)
        elif not self.ovs_client.portExists(self.external_iface):
            self.ovs_client.addPort('cygnet0', self.external_iface)
        ip = IPDB()
        ifaces = ip.interfaces
        ifaces.cygnet0.begin()
        addrs= ip.interfaces[self.external_iface].ipaddr.raw
        addr = None
        for address, attrs in addrs.items():
            if __getIPv4Addr__([address]) == None:
                continue
            addr = address
        ifaces.cygnet0.add_ip(addr[0], int(addr[1]))
        ifaces.cygnet0.up()
        ifaces.cygnet0.commit()
        ifaces[self.external_iface].begin()
        ifaces[self.external_iface].down()
        ifaces[self.external_iface].commit()

        ifaces[self.external_iface].begin()
        ifaces[self.external_iface].up()
        ifaces[self.external_iface].commit()

        ip.release()
开发者ID:SaadTalaat,项目名称:cygnet-common,代码行数:27,代码来源:interfaces.py


示例5: test_create_gre

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

        ifL = self.get_ifname()
        ifV = self.get_ifname()
        with self.ip.create(kind='dummy', ifname=ifL) as i:
            i.add_ip('172.16.0.1/24')
            i.up()

        self.ip.create(kind='gre',
                       ifname=ifV,
                       gre_local='172.16.0.1',
                       gre_remote='172.16.0.2',
                       gre_ttl=16).commit()

        ip2 = IPDB()
        ifdb = ip2.interfaces
        try:
            assert ifdb[ifV].gre_local == '172.16.0.1'
            assert ifdb[ifV].gre_remote == '172.16.0.2'
            assert ifdb[ifV].gre_ttl == 16
        except Exception:
            raise
        finally:
            ip2.release()
开发者ID:0x90,项目名称:pyroute2,代码行数:25,代码来源:test_ipdb.py


示例6: initContainerNetwork

 def initContainerNetwork(self, network=None):
     if not network:
         try:
             network = Network(None)
             network.name = 'cygnet_internal'
             network.address = self['internal_ip']
             if not self.ovs_client.bridgeExists(network.name):
                 self.ovs_client.addBridge(network.name)
                 self.ovs_client.setBridgeProperty(network.name,
                                                   'stp_enable',
                                                   True)
         except KeyError as e:
             print("OpenvSwitch: CYGNET_INTERNAL_IP \
                     environment variable not found")
             raise e
     else:
         network.name = "cygnet_" + network.id[:8]
         if not self.ovs_client.bridgeExists(network.name):
             self.ovs_client.addBridge(network.name)
             self.ovs_client.setBridgeProperty(network.name,
                                               'stp_enable',
                                               True)
     ip = IPDB()
     ifaces = ip.interfaces
     ifaces[network.name].begin()
     ifaces[network.name].add_ip(network.address, network.mask)
     ifaces[network.name].up()
     ifaces[network.name].commit()
     ip.release()
     self.interfaces.append(network)
     return network
开发者ID:SaadTalaat,项目名称:cygnet-common,代码行数:31,代码来源:interfaces.py


示例7: test_create_vxlan

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

        ifL = self.get_ifname()
        ifV = self.get_ifname()
        ifdb = self.ip.interfaces

        self.ip.create(kind='dummy',
                       ifname=ifL).commit()
        self.ip.create(kind='vxlan',
                       ifname=ifV,
                       vxlan_link=ifdb[ifL],
                       vxlan_id=101,
                       vxlan_group='239.1.1.1').commit()

        ip2 = IPDB()
        ifdb = ip2.interfaces

        try:
            assert ifdb[ifV].vxlan_link == ifdb[ifL].index
            assert ifdb[ifV].vxlan_group == '239.1.1.1'
            assert ifdb[ifV].vxlan_id == 101
        except Exception:
            raise
        finally:
            ip2.release()
开发者ID:0x90,项目名称:pyroute2,代码行数:26,代码来源:test_ipdb.py


示例8: test_ipdb

 def test_ipdb(self):
     require_user('root')
     ip = IPDB()
     try:
         assert ip._nl_async is False
         assert len(ip.interfaces.keys()) > 1
     except:
         raise
     finally:
         ip.release()
开发者ID:0xD3ADB33F,项目名称:pyroute2,代码行数:10,代码来源:test_eventlet.py


示例9: destroyInterface

	def destroyInterface(self):
		ipdb = IPDB()

		with ipdb.interfaces[self.bridge_iface] as i:
			i.del_port(ipdb.interfaces[self.veth0])

		with ipdb.interfaces[self.veth0] as i:
			i.remove()

		ipdb.release()
开发者ID:Zaynullin,项目名称:sensors,代码行数:10,代码来源:NetworkNamespace.py


示例10: deleteService

def deleteService(name, terminalName):
    if_svc_name = name
    if_terminal_name = name + '_' + terminalName
    ip_host = IPDB()
    with ip_host.interfaces[if_terminal_name] as veth:
        veth.remove()
    ip_host.release()
    subprocess.call(["ovs-vsctl", "del-port", "vs-" + name, if_svc_name])
    subprocess.call(["ovs-vsctl", "del-port", "br0", if_terminal_name])
    subprocess.call(["ovs-vsctl", "del-br", "vs-" + name])
    return json.dumps({ 'status' : 'deleted service'})
开发者ID:michaelhenkel,项目名称:tcc,代码行数:11,代码来源:terminalServer.py


示例11: _TestDhcpClient

class _TestDhcpClient(object):

    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)

    def teardown(self):
        # read pid from file and kill the server
        with open('udhcpd.pid', 'r') as pid_file:
            pid = int(pid_file.read())
            os.kill(pid, 15)
        # teardown interfaces (enough to remove only master)
        self.ip.interfaces[self.if1].remove().commit()
        # release IPDB
        self.ip.release()
        # remove configuration file
        os.unlink('udhcpd.conf')
        # collect garbage
        gc.collect()

    def test_defaults(self):
        msg = dhclient.action(self.if2)
        assert msg['yiaddr'].startswith('172.16.101.')
        assert msg['op'] == BOOTREPLY
        assert msg['options']['message_type'] == DHCPACK
        assert msg['options']['router'] == ['172.16.101.1']
        assert msg['options']['server_id'] == '172.16.101.1'
        assert msg['options']['subnet_mask'] == '255.255.255.0'
        assert set(msg['options']['name_server']) ==\
            set(('172.16.101.1', '172.16.101.2'))
开发者ID:celebdor,项目名称:pyroute2,代码行数:52,代码来源:test_dhcp.py


示例12: initalize

 def initalize(self):
     ip = IPDB()
     try:
         # Check if public interface is up
         self.addr = __getIPv4Addr__(list(ip.interfaces.br1.ipaddr))
         self.addr = self.addr[0], str(self.addr[1])
         self.interfaces.append(('br1', self.addr))
     except Exception as e:
         print(e)
     finally:
         ip.release()
     self.range_buckets[int(self.addr[0].split(".")[-1])] = 1
     return self.addr
开发者ID:Cygnus-Inc,项目名称:cygnet-common,代码行数:13,代码来源:interfaces.py


示例13: 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


示例14: __createNetns

  def __createNetns(self, phyIfaceIndex):
    netnsName = self.__getNetnsName()
    (pvdIfaceName, pvdIfaceIndex) = self.__getPvdIfaceParams()
    netns.create(netnsName)
    LOG.debug('network namespace {0} created'.format(netnsName))

    # create a virtual interface where PvD parameters are going to be configured, then move the interface to the new network namespace
    self.ipRoot.link_create(ifname=pvdIfaceName, index=pvdIfaceIndex, kind=self.__PVD_IFACE_TYPE, link=phyIfaceIndex)
    LOG.debug('macvlan {0} created in default network namespace'.format(pvdIfaceName))
    pvdIfaceIndex = self.ipRoot.link_lookup(ifname=pvdIfaceName)
    self.ipRoot.link('set', index=pvdIfaceIndex[0], net_ns_fd=netnsName)
    LOG.debug('macvlan {0} moved to network namespace {1}'.format(pvdIfaceName, netnsName))

    # change the namespace and get new NETLINK handles to operate in new namespace
    netns.setns(netnsName)
    LOG.debug('network namespace switched to {0}'.format(netnsName))
    ip = IPRoute()
    ipdb = IPDB()
    ipdb.register_callback(self.__onIfaceStateChange)
    # disable kernel to auto-configure the interface associated with the PvD, let the pvdman to solely control interface configuration
    acceptRaConfFile = self.__ACCEPT_RA_CONF_FILE.replace(self.__IFACENAME_REPLACE_PATTERN, pvdIfaceName)
    acceptRaConfFile = open(acceptRaConfFile, 'w')
    acceptRaConfFile.write('0')
    LOG.debug('processing of RAs by kernel disabled in {0}'.format(acceptRaConfFile.name))
    # return to a default network namespace to not cause a colision with other modules
    # ip and ipdb handles continue to work in the target network namespace
    netns.setns(self.__NETNS_DEFAULT_NAME)
    LOG.debug('network namespace switched to default')

    # get new index since interface has been moved to a different namespace
    loIfaceIndex = ip.link_lookup(ifname=self.__LOOPBACK_IFACE_NAME)
    if (len(loIfaceIndex) > 0):
      loIfaceIndex = loIfaceIndex[0]
    pvdIfaceIndex = ip.link_lookup(ifname=pvdIfaceName)
    if (len(pvdIfaceIndex) > 0):
      pvdIfaceIndex = pvdIfaceIndex[0]

    # start interfaces
    ip.link_up(loIfaceIndex)
    ip.link_up(pvdIfaceIndex)

    # clear network configuration if exists
    ip.flush_addr(index=pvdIfaceIndex)
    ip.flush_routes(index=pvdIfaceIndex)
    ip.flush_rules(index=pvdIfaceIndex)

    LOG.debug('macvlan {0} in network namespace {1} initialized'.format(pvdIfaceName, netnsName))

    return (netnsName, pvdIfaceName, ip)
开发者ID:l30nard0,项目名称:mif,代码行数:49,代码来源:pvdman.py


示例15: initalize

 def initalize(self):
     # check if our setup already exists
     self.__ovs_setup()
     ip = IPDB()
     try:
         # Check if public interface is up
         self.addr = __getIPv4Addr__(list(ip.interfaces.cygnet0.ipaddr))
         self.addr = self.addr[0], str(self.addr[1])
         #self.interfaces.append(('cygnet0', self.addr))
     except Exception as e:
         raise e
     finally:
         ip.release()
     self.range_buckets[int(self.addr[0].split(".")[-1])] = 1
     return self.addr
开发者ID:SaadTalaat,项目名称:cygnet-common,代码行数:15,代码来源:interfaces.py


示例16: createService

def createService(name, terminalName, svcId):
    subprocess.call(["ovs-vsctl", "add-br", "vs-" + name])
    if_svc_name = name
    if_terminal_name = name + '_' + terminalName
    ip_host = IPDB()
    ip_host.create(ifname=if_svc_name, kind='veth', peer=if_terminal_name).commit()
    with ip_host.interfaces[if_svc_name] as veth:
        veth.up()
    with ip_host.interfaces[if_terminal_name] as veth:
        veth.up()
    ip_host.release()
    subprocess.call(["ovs-vsctl", "add-port", "vs-" + name, if_svc_name])
    subprocess.call(["ovs-vsctl", "add-port", "br0", if_terminal_name])
    subprocess.call(["ovs-vsctl", "set", "port", if_terminal_name, "tag=" + str(svcId)])
    return json.dumps({ 'status' : 'created service'})
开发者ID:michaelhenkel,项目名称:tcc,代码行数:15,代码来源:terminalServer.py


示例17: createInterface

	def createInterface(self):
		ipdb = IPDB()
		ipdb.create(ifname=self.veth0, kind='veth', peer=self.veth1).commit()

		with ipdb.interfaces[self.veth0] as i:
			i.up()

		with ipdb.interfaces[self.veth1] as i:
			i.up()
			i.net_ns_fd = self.nsname

		with ipdb.interfaces[self.bridge_iface] as i:
			i.add_port(ipdb.interfaces[self.veth0])

		ipdb.release()
开发者ID:Zaynullin,项目名称:sensors,代码行数:15,代码来源:NetworkNamespace.py


示例18: setup

 def setup(self):
     self.ipdb = IPDB()
     self.io = io.BytesIO()
     self.con = subprocess.Popen(['python', '%s/bin/ipdb' % TMPDIR],
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
开发者ID:celebdor,项目名称:pyroute2,代码行数:7,代码来源:test_cli.py


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pyroute2.IPRoute类代码示例发布时间:2022-05-27
下一篇:
Python pyroms_toolbox.nc_create_roms_file函数代码示例发布时间: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