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

Python log.output函数代码示例

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

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



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

示例1: errRun

def errRun( *cmd, **kwargs ):
    """Run a command and return stdout, stderr and return code
       cmd: string or list of command and args
       stderr: STDOUT to merge stderr with stdout
       shell: run command using shell
       echo: monitor output to console"""
    # By default we separate stderr, don't run in a shell, and don't echo
    stderr = kwargs.get( 'stderr', PIPE )
    shell = kwargs.get( 'shell', False )
    echo = kwargs.get( 'echo', False )
    if echo:
        # cmd goes to stderr, output goes to stdout
        info( cmd, '\n' )
    if len( cmd ) == 1:
        cmd = cmd[ 0 ]
    # Allow passing in a list or a string
    if isinstance( cmd, str ) and not shell:
        cmd = cmd.split( ' ' )
        cmd = [ str( arg ) for arg in cmd ]
    elif isinstance( cmd, list ) and shell:
        cmd = " ".join( arg for arg in cmd )
    debug( '*** errRun:', cmd, '\n' )
    popen = Popen( cmd, stdout=PIPE, stderr=stderr, shell=shell )
    # We use poll() because select() doesn't work with large fd numbers,
    # and thus communicate() doesn't work either
    out, err = '', ''
    poller = poll()
    poller.register( popen.stdout, POLLIN )
    fdtofile = { popen.stdout.fileno(): popen.stdout }
    outDone, errDone = False, True
    if popen.stderr:
        fdtofile[ popen.stderr.fileno() ] = popen.stderr
        poller.register( popen.stderr, POLLIN )
        errDone = False
    while not outDone or not errDone:
        readable = poller.poll()
        for fd, event in readable:
            f = fdtofile[ fd ]
            if event & POLLIN:
                data = f.read( 1024 )
                if echo:
                    output( data )
                if f == popen.stdout:
                    out += data
                    if data == '':
                        outDone = True
                elif f == popen.stderr:
                    err += data
                    if data == '':
                        errDone = True
            else:  # POLLHUP or something unexpected
                if f == popen.stdout:
                    outDone = True
                elif f == popen.stderr:
                    errDone = True
                poller.unregister( fd )

    returncode = popen.wait()
    debug( out, err, returncode )
    return out, err, returncode
开发者ID:NvanAdrichem,项目名称:mininet,代码行数:60,代码来源:util.py


示例2: waitForNode

 def waitForNode( self, node ):
     "Wait for a node to finish, and  print its output."
     # Pollers
     nodePoller = poll()
     nodePoller.register( node.stdout )
     bothPoller = poll()
     bothPoller.register( self.stdin, POLLIN )
     bothPoller.register( node.stdout, POLLIN )
     if self.isatty():
         # Buffer by character, so that interactive
         # commands sort of work
         quietRun( 'stty -icanon min 1' )
     while True:
         try:
             bothPoller.poll()
             # XXX BL: this doesn't quite do what we want.
             if False and self.inputFile:
                 key = self.inputFile.read( 1 )
                 if key is not '':
                     node.write(key)
                 else:
                     self.inputFile = None
             if isReadable( self.inPoller ):
                 key = self.stdin.read( 1 )
                 node.write( key )
             if isReadable( nodePoller ):
                 data = node.monitor()
                 output( data )
             if not node.waiting:
                 break
         except KeyboardInterrupt:
             node.sendInt()
开发者ID:ActiveCK,项目名称:mininet,代码行数:32,代码来源:cli.py


示例3: ping

 def ping(self, hosts=None):
     """Ping between all specified hosts.
        hosts: list of hosts
        returns: ploss packet loss percentage"""
     # should we check if running?
     packets = 0
     lost = 0
     ploss = None
     if not hosts:
         hosts = self.hosts
         output("*** Ping: testing ping reachability\n")
     for node in hosts:
         # print "node:" ,node # only test~lol
         output("%s -> " % node.name)
         for dest in hosts:
             if node != dest:
                 result = node.cmd("ping -c1 " + dest.IP())
                 sent, received = self._parsePing(result)
                 packets += sent
                 if received > sent:
                     error("*** Error: received too many packets")
                     error("%s" % result)
                     node.cmdPrint("route")
                     exit(1)
                 lost += sent - received
                 output(("%s " % dest.name) if received else "X ")
         output("\n")
         ploss = 100 * lost / packets
     output("*** Results: %i%% dropped (%d/%d lost)\n" % (ploss, lost, packets))
     return ploss
开发者ID:09zwcbupt,项目名称:mininet,代码行数:30,代码来源:net.py


示例4: ping

    def ping( self, hosts=None, timeout=None ):
        """Ping between all specified hosts.
           hosts: list of hosts
           timeout: time to wait for a response, as string
           returns: ploss packet loss percentage"""
        # should we check if running?
        packets = 0
        lost = 0
        ploss = None
	if not hosts:
            hosts = self.hosts[1:]
            output( '*** Ping: testing ping reachability\n' )
        for node in hosts:
            output( '%s -> ' % node.name )
            for dest in hosts:
                if node != dest:
                    opts = ''
                    if timeout:
                        opts = '-W %s' % timeout
		    result = node.cmd( 'ping -c1 %s %s' % (opts, dest.IP()) )
		    sent, received = self._parsePing( result )
                    packets += sent
                    if received > sent:
                        error( '*** Error: received too many packets' )
                        error( '%s' % result )
                        node.cmdPrint( 'route' )
                        exit( 1 )
                    lost += sent - received
                    output( ( '%s ' % dest.name ) if received else 'X ' )
            output( '\n' )
            ploss = 100 * lost / packets
        output( "*** Results: %i%% dropped (%d/%d lost)\n" %
                ( ploss, lost, packets ) )
        return ploss
开发者ID:arjunkrishnapr,项目名称:mininet,代码行数:34,代码来源:net.py


示例5: do_bgIperf

def do_bgIperf(self, line):
    args = line.split()
    if not args:
        output("Provide a list of hosts.\n")

    # Try to parse the '-t' argument as the number of seconds
    seconds = 10
    for i, arg in enumerate(args):
        if arg == "-t":
            if i + 1 < len(args):
                try:
                    seconds = int(args[i + 1])
                except ValueError:
                    error("Could not parse number of seconds: %s", args[i + 1])
                del (args[i + 1])
            del args[i]

    hosts = []
    err = False
    for arg in args:
        if arg not in self.mn:
            err = True
            error("node '%s' not in network\n" % arg)
        else:
            hosts.append(self.mn[arg])
    if "bgIperf" in dir(self.mn) and not err:
        self.mn.bgIperf(hosts, seconds=seconds)
开发者ID:santuari,项目名称:onos,代码行数:27,代码来源:onosnet.py


示例6: runCpuLimitTest

 def runCpuLimitTest(self, cpu, duration=5):
     """run CPU limit test with 'while true' processes.
     cpu: desired CPU fraction of each host
     duration: test duration in seconds
     returns a single list of measured CPU fractions as floats.
     """
     pct = cpu * 100
     info("*** Testing CPU %.0f%% bandwidth limit\n" % pct)
     hosts = self.hosts
     for h in hosts:
         h.cmd("while true; do a=1; done &")
     pids = [h.cmd("echo $!").strip() for h in hosts]
     pids_str = ",".join(["%s" % pid for pid in pids])
     cmd = "ps -p %s -o pid,%%cpu,args" % pids_str
     # It's a shame that this is what pylint prefers
     outputs = []
     for _ in range(duration):
         sleep(1)
         outputs.append(quietRun(cmd).strip())
     for h in hosts:
         h.cmd("kill $!")
     cpu_fractions = []
     for test_output in outputs:
         # Split by line.  Ignore first line, which looks like this:
         # PID %CPU COMMAND\n
         for line in test_output.split("\n")[1:]:
             r = r"\d+\s*(\d+\.\d+)"
             m = re.search(r, line)
             if m is None:
                 error("*** Error: could not extract CPU fraction: %s\n" % line)
                 return None
             cpu_fractions.append(float(m.group(1)))
     output("*** Results: %s\n" % cpu_fractions)
     return cpu_fractions
开发者ID:ruifcardoso,项目名称:mininet,代码行数:34,代码来源:net.py


示例7: do_placement

 def do_placement(self, _line):
     "Describe node placement"
     mn = self.mn
     nodes = mn.hosts + mn.switches + mn.controllers
     for server in mn.servers:
         names = [n.name for n in nodes if hasattr(n, "server") and n.server == server]
         output("%s: %s\n" % (server, " ".join(names)))
开发者ID:XianliangJ,项目名称:Mininet-WiFi,代码行数:7,代码来源:clustercli.py


示例8: PMUPingPDC

def PMUPingPDC(net, pmu, pdc, timeout):
    time.sleep(5)
    pmu_host = net.getNodeByName(pmu)
    pdc_host = net.getNodeByName(pdc)
    output('%s(%s) ping -c1 %s(%s)' % (pmu, pmu_host.IP(), pdc, pdc_host.IP()))
    result = pmu_host.cmd('ping -W %d -c1 %s' % (timeout, pdc_host.IP()))
    output(result)
开发者ID:atirados,项目名称:PowerSystemDemo,代码行数:7,代码来源:bus_system.py


示例9: waitForNode

 def waitForNode( self, node ):
     "Wait for a node to finish, and  print its output."
     # Pollers
     nodePoller = poll()
     nodePoller.register( node.stdout )
     bothPoller = poll()
     bothPoller.register( self.stdin )
     bothPoller.register( node.stdout )
     while True:
         try:
             bothPoller.poll()
             # XXX BL: this doesn't quite do what we want.
             if False and self.inputFile:
                 key = self.inputFile.read( 1 )
                 if key is not '':
                     node.write(key)
                 else:
                     self.inputFile = None
             if isReadable( self.inPoller ):
                 key = self.stdin.read( 1 )
                 node.write( key )
             if isReadable( nodePoller ):
                 data = node.monitor()
                 output( data )
             if not node.waiting:
                 break
         except KeyboardInterrupt:
             node.sendInt()
开发者ID:sandeephebbani,项目名称:mininet,代码行数:28,代码来源:cli.py


示例10: __init__

 def __init__( self, mininet, stdin=sys.stdin, script=None ):
     self.mn = mininet
     self.nodelist = self.mn.controllers + self.mn.switches + self.mn.hosts
     self.nodemap = {}  # map names to Node objects
     for node in self.nodelist:
         self.nodemap[ node.name ] = node
     # Attempt to handle input
     self.stdin = stdin
     self.inPoller = poll()
     self.inPoller.register( stdin )
     self.inputFile = script
     Cmd.__init__( self )
     info( '*** Starting CLI:\n' )
     if self.inputFile:
         self.do_source( self.inputFile )
         return
     while True:
         try:
             # Make sure no nodes are still waiting
             for node in self.nodelist:
                 while node.waiting:
                     node.sendInt()
                     node.monitor()
             if self.isatty():
                 quietRun( 'stty sane' )
             self.cmdloop()
             break
         except KeyboardInterrupt:
             output( '\nInterrupt\n' )
开发者ID:sandeephebbani,项目名称:mininet,代码行数:29,代码来源:cli.py


示例11: hostPing

 def hostPing(self, rate, duration_time=10):
     # rate is the arp request per secend per host
     rate = float(rate)
     host_numb = len(self.hosts)
     output("host_numb:%d\n" % host_numb)
     net_rate = int(host_numb * rate)
     self.netPing(net_rate, duration_time)
开发者ID:Guzeping,项目名称:Mininet,代码行数:7,代码来源:net.py


示例12: do_px

 def do_px( self, line ):
     """Execute a Python statement.
         Node names may be used, e.g.: px print h1.cmd('ls')"""
     try:
         exec( line, globals(), self.getLocals() )
     except Exception, e:
         output( str( e ) + '\n' )
开发者ID:ActiveCK,项目名称:mininet,代码行数:7,代码来源:cli.py


示例13: __init__

 def __init__( self, mininet, stdin=sys.stdin, script=None ):
     self.mn = mininet
     # Local variable bindings for py command
     self.locals = { 'net': mininet }
     # Attempt to handle input
     self.stdin = stdin
     self.inPoller = poll()
     self.inPoller.register( stdin )
     self.inputFile = script
     Cmd.__init__( self )
     info( '*** Starting CLI:\n' )
     if self.inputFile:
         self.do_source( self.inputFile )
         return
     while True:
         try:
             # Make sure no nodes are still waiting
             for node in self.mn.values():
                 while node.waiting:
                     node.sendInt()
                     node.monitor()
             if self.isatty():
                 quietRun( 'stty sane' )
             self.cmdloop()
             break
         except KeyboardInterrupt:
             output( '\nInterrupt\n' )
开发者ID:FlowForwarding,项目名称:mininet,代码行数:27,代码来源:cli.py


示例14: build

    def build(self, ovs_type, ports_sock, test_name, dpids,
              n_tagged=0, tagged_vid=100, n_untagged=0, links_per_host=0,
              n_extended=0, e_cls=None, tmpdir=None, hw_dpid=None, host_namespace=None):
        if not host_namespace:
            host_namespace = {}

        for dpid in dpids:
            serialno = mininet_test_util.get_serialno(
                ports_sock, test_name)
            sid_prefix = self._get_sid_prefix(serialno)
            for host_n in range(n_tagged):
                self._add_tagged_host(sid_prefix, tagged_vid, host_n)
            for host_n in range(n_untagged):
                self._add_untagged_host(sid_prefix, host_n, host_namespace.get(host_n, True))
            for host_n in range(n_extended):
                self._add_extended_host(sid_prefix, host_n, e_cls, tmpdir)
            switch_cls = FaucetSwitch
            if hw_dpid and hw_dpid == dpid:
                remap_dpid = str(int(dpid) + 1)
                output('bridging hardware switch DPID %s (%x) dataplane via OVS DPID %s (%x)' % (
                    dpid, int(dpid), remap_dpid, int(remap_dpid)))
                dpid = remap_dpid
                switch_cls = NoControllerFaucetSwitch
            switch = self._add_faucet_switch(sid_prefix, dpid, ovs_type, switch_cls)
            self._add_links(switch, self.hosts(), links_per_host)
开发者ID:anarkiwi,项目名称:faucet,代码行数:25,代码来源:mininet_test_topo.py


示例15: waitListening

def waitListening(client, server, port):
    "Wait until server is listening on port"
    if not "telnet" in client.cmd("which telnet"):
        raise Exception("Could not find telnet")
    cmd = 'sh -c "echo A | telnet -e A %s %s"' % (server.IP(), port)
    while "Connected" not in client.cmd(cmd):
        output("waiting for", server, "to listen on port", port, "\n")
        sleep(0.5)
开发者ID:roterdam,项目名称:Computer_Networks,代码行数:8,代码来源:parkinglot.py


示例16: waitListening

def waitListening(client, server, port):
    "Wait until server is listening on port"
    if not 'telnet' in client.cmd('which telnet'):
        raise Exception('Could not find telnet')
    cmd = ('sh -c "echo A | telnet -e A %s %s"' % (server.IP(), port))
    while 'Connected' not in client.cmd(cmd):
        output('waiting for', server, 'to listen on port', port, '\n')
        sleep(.5)
开发者ID:hodiapa,项目名称:ScienceDMZ,代码行数:8,代码来源:measure.py


示例17: do_placement

 def do_placement( self ):
     "Describe node placement"
     mn = self.mn
     nodes = mn.hosts + mn.switches + mn.controllers
     for server in mn.servers:
         names = [ n.name for n in nodes if hasattr( n, 'server' )
                   and n.server == server ]
         output( '%s: %s\n' % ( server, ' '.join( names ) ) )
开发者ID:xiaozhou,项目名称:mininet-cluster,代码行数:8,代码来源:clustercli.py


示例18: startIperf

def startIperf( host, hostsDST ):
    output( '\n\n' )    
    for dst in hostsDST:
        if dst.IP() != host.IP():
            hostsAux = []
            hostsAux.append(host)
            hostsAux.append(dst)
            iperf(hosts = hostsAux )        
开发者ID:intrig-unicamp,项目名称:ALTO-as-a-Service,代码行数:8,代码来源:Iperf_test1_mininetCode.py


示例19: show_topology

def show_topology():
    output("------- Topology -------\n")
    for s in net.switches:
        output(s.name, '<->')
        for intf in s.intfs.values():
            name = s.connection.get(intf, (None, 'Unknown ') ) [ 1 ]
            output( ' %s' % name )
        output('\n')
    output('\n')
开发者ID:SABER087,项目名称:floodlight-test,代码行数:9,代码来源:IslandTestHostMobility2Topo.py


示例20: do_dpctl

 def do_dpctl(self, line):
     "Run dpctl (or ovs-ofctl) command on all switches."
     args = line.split()
     if len(args) < 1:
         error("usage: dpctl command [arg1] [arg2] ...\n")
         return
     for sw in self.mn.switches:
         output("*** " + sw.name + " " + ("-" * 72) + "\n")
         output(sw.dpctl(*args))
开发者ID:RuiZhou,项目名称:mininet,代码行数:9,代码来源:cli.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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