updated all print calls to use print() method for 2/3
This commit is contained in:
parent
e58cbe9421
commit
feebd8704f
11 changed files with 89 additions and 95 deletions
|
@ -65,7 +65,7 @@ def cmd(node, exec_cmd):
|
|||
msgdata = server.sock.recv(msglen)
|
||||
|
||||
# If we get the right response return the results
|
||||
print "received response message: %s" % MessageTypes(msgtype)
|
||||
print("received response message: %s" % MessageTypes(msgtype))
|
||||
if msgtype == MessageTypes.EXECUTE.value:
|
||||
msg = coreapi.CoreExecMessage(msgflags, msghdr, msgdata)
|
||||
result = msg.get_tlv(ExecuteTlvs.RESULT.value)
|
||||
|
@ -120,7 +120,7 @@ def main():
|
|||
port = int(daemonport[1])
|
||||
else:
|
||||
port = CORE_API_PORT
|
||||
print "connecting to daemon at %s:%d" % (daemon, port)
|
||||
print("connecting to daemon at %s:%d" % (daemon, port))
|
||||
session.broker.addserver(daemon, daemonip, port)
|
||||
|
||||
# Set the local session id to match the port.
|
||||
|
@ -145,7 +145,7 @@ def main():
|
|||
|
||||
number_of_nodes = options.numnodes
|
||||
|
||||
print "creating %d remote nodes with addresses from %s" % (options.numnodes, prefix)
|
||||
print("creating %d remote nodes with addresses from %s" % (options.numnodes, prefix))
|
||||
|
||||
# create remote nodes via API
|
||||
for i in range(1, number_of_nodes + 1):
|
||||
|
@ -175,13 +175,11 @@ def main():
|
|||
session.broker.handlerawmsg(msg)
|
||||
|
||||
# Get the ip or last node and ping it from the first
|
||||
print "Pinging from the first to the last node"
|
||||
print("Pinging from the first to the last node")
|
||||
pingip = cmd(n[-1], "ip -4 -o addr show dev eth0").split()[3].split("/")[0]
|
||||
print cmd(n[1], "ping -c 5 " + pingip)
|
||||
|
||||
print "elapsed time: %s" % (datetime.datetime.now() - start)
|
||||
|
||||
print "To stop this session, use the core-cleanup script on the remote daemon server."
|
||||
print(cmd(n[1], "ping -c 5 " + pingip))
|
||||
print("elapsed time: %s" % (datetime.datetime.now() - start))
|
||||
print("To stop this session, use the core-cleanup script on the remote daemon server.")
|
||||
raw_input("press enter to exit")
|
||||
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ def main():
|
|||
port = int(slaveport[1])
|
||||
else:
|
||||
port = CORE_API_PORT
|
||||
print "connecting to slave at %s:%d" % (slave, port)
|
||||
print("connecting to slave at %s:%d" % (slave, port))
|
||||
session.broker.addserver(slave, slave, port)
|
||||
session.broker.setupserver(slave)
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
@ -79,8 +79,8 @@ def main():
|
|||
switch.setposition(x=80, y=50)
|
||||
num_local = options.numnodes / 2
|
||||
num_remote = options.numnodes / 2 + options.numnodes % 2
|
||||
print "creating %d (%d local / %d remote) nodes with addresses from %s" % \
|
||||
(options.numnodes, num_local, num_remote, prefix)
|
||||
print("creating %d (%d local / %d remote) nodes with addresses from %s" % \
|
||||
(options.numnodes, num_local, num_remote, prefix))
|
||||
for i in range(1, num_local + 1):
|
||||
node = session.create_node(cls=core.nodes.base.CoreNode, name="n%d" % i, _id=i)
|
||||
node.newnetif(switch, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
|
||||
|
@ -120,9 +120,9 @@ def main():
|
|||
# start a shell on node 1
|
||||
n[1].client.term("bash")
|
||||
|
||||
print "elapsed time: %s" % (datetime.datetime.now() - start)
|
||||
print "To stop this session, use the 'core-cleanup' script on this server"
|
||||
print "and on the remote slave server."
|
||||
print("elapsed time: %s" % (datetime.datetime.now() - start))
|
||||
print("To stop this session, use the 'core-cleanup' script on this server")
|
||||
print("and on the remote slave server.")
|
||||
|
||||
|
||||
if __name__ == "__main__" or __name__ == "__builtin__":
|
||||
|
|
|
@ -115,16 +115,16 @@ def main():
|
|||
start = datetime.datetime.now()
|
||||
prefix = ipaddress.Ipv4Prefix("10.83.0.0/16")
|
||||
|
||||
print "Testing how many network namespace nodes this machine can create."
|
||||
print " - %s" % linuxversion()
|
||||
print("Testing how many network namespace nodes this machine can create.")
|
||||
print(" - %s" % linuxversion())
|
||||
mem = memfree()
|
||||
print " - %.02f GB total memory (%.02f GB swap)" % (mem["total"] / GBD, mem["stotal"] / GBD)
|
||||
print " - using IPv4 network prefix %s" % prefix
|
||||
print " - using wait time of %s" % options.waittime
|
||||
print " - using %d nodes per bridge" % options.bridges
|
||||
print " - will retry %d times on failure" % options.retries
|
||||
print " - adding these services to each node: %s" % options.services
|
||||
print " "
|
||||
print(" - %.02f GB total memory (%.02f GB swap)" % (mem["total"] / GBD, mem["stotal"] / GBD))
|
||||
print(" - using IPv4 network prefix %s" % prefix)
|
||||
print(" - using wait time of %s" % options.waittime)
|
||||
print(" - using %d nodes per bridge" % options.bridges)
|
||||
print(" - will retry %d times on failure" % options.retries)
|
||||
print(" - adding these services to each node: %s" % options.services)
|
||||
print(" ")
|
||||
|
||||
lfp = None
|
||||
if options.logfile is not None:
|
||||
|
@ -138,7 +138,7 @@ def main():
|
|||
session = Session(1)
|
||||
switch = session.create_node(cls=core.nodes.network.SwitchNode)
|
||||
switchlist.append(switch)
|
||||
print "Added bridge %s (%d)." % (switch.brname, len(switchlist))
|
||||
print("Added bridge %s (%d)." % (switch.brname, len(switchlist)))
|
||||
|
||||
i = 0
|
||||
retry_count = options.retries
|
||||
|
@ -149,9 +149,9 @@ def main():
|
|||
if 0 < options.bridges <= switch.numnetif():
|
||||
switch = session.create_node(cls=core.nodes.network.SwitchNode)
|
||||
switchlist.append(switch)
|
||||
print "\nAdded bridge %s (%d) for node %d." % (switch.brname, len(switchlist), i)
|
||||
print("\nAdded bridge %s (%d) for node %d." % (switch.brname, len(switchlist), i))
|
||||
except Exception, e:
|
||||
print "At %d bridges (%d nodes) caught exception:\n%s\n" % (len(switchlist), i - 1, e)
|
||||
print("At %d bridges (%d nodes) caught exception:\n%s\n" % (len(switchlist), i - 1, e))
|
||||
break
|
||||
|
||||
# create a node
|
||||
|
@ -164,11 +164,11 @@ def main():
|
|||
session.services.boot_services(n)
|
||||
nodelist.append(n)
|
||||
if i % 25 == 0:
|
||||
print "\n%s nodes created " % i,
|
||||
print("\n%s nodes created " % i,)
|
||||
mem = memfree()
|
||||
free = mem["free"] + mem["buff"] + mem["cached"]
|
||||
swap = mem["stotal"] - mem["sfree"]
|
||||
print "(%.02f/%.02f GB free/swap)" % (free / GBD, swap / GBD),
|
||||
print("(%.02f/%.02f GB free/swap)" % (free / GBD, swap / GBD),)
|
||||
if lfp:
|
||||
lfp.write("%d," % i)
|
||||
lfp.write("%s\n" % ",".join(str(mem[x]) for x in MEMKEYS))
|
||||
|
@ -178,20 +178,20 @@ def main():
|
|||
sys.stdout.flush()
|
||||
time.sleep(options.waittime)
|
||||
except Exception, e:
|
||||
print "At %d nodes caught exception:\n" % i, e
|
||||
print("At %d nodes caught exception:\n" % i, e)
|
||||
if retry_count > 0:
|
||||
print "\nWill retry creating node %d." % i
|
||||
print("\nWill retry creating node %d." % i)
|
||||
shutil.rmtree(n.nodedir, ignore_errors=True)
|
||||
retry_count -= 1
|
||||
i -= 1
|
||||
time.sleep(options.waittime)
|
||||
continue
|
||||
else:
|
||||
print "Stopping at %d nodes!" % i
|
||||
print("Stopping at %d nodes!" % i)
|
||||
break
|
||||
|
||||
if i == options.numnodes:
|
||||
print "Stopping at %d nodes due to numnodes option." % i
|
||||
print("Stopping at %d nodes due to numnodes option." % i)
|
||||
break
|
||||
# node creation was successful at this point
|
||||
retry_count = options.retries
|
||||
|
@ -200,8 +200,8 @@ def main():
|
|||
lfp.flush()
|
||||
lfp.close()
|
||||
|
||||
print "elapsed time: %s" % (datetime.datetime.now() - start)
|
||||
print "Use the core-cleanup script to remove nodes and bridges."
|
||||
print("elapsed time: %s" % (datetime.datetime.now() - start))
|
||||
print("Use the core-cleanup script to remove nodes and bridges.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -171,13 +171,13 @@ class ManetExperiment(object):
|
|||
|
||||
def info(self, msg):
|
||||
''' Utility method for writing output to stdout. '''
|
||||
print msg
|
||||
print(msg)
|
||||
sys.stdout.flush()
|
||||
self.log(msg)
|
||||
|
||||
def warn(self, msg):
|
||||
''' Utility method for writing output to stderr. '''
|
||||
print >> sys.stderr, msg
|
||||
sys.stderr.write(msg)
|
||||
sys.stderr.flush()
|
||||
self.log(msg)
|
||||
|
||||
|
@ -204,7 +204,7 @@ class ManetExperiment(object):
|
|||
""" Write to the log file, if any. """
|
||||
if not self.logfp:
|
||||
return
|
||||
print >> self.logfp, msg
|
||||
self.logfp.write(msg)
|
||||
|
||||
def logdata(self, nbrs, mdrs, lsdbs, krs, zrs):
|
||||
""" Dump experiment parameters and data to the log file. """
|
||||
|
@ -368,12 +368,12 @@ class Cmd:
|
|||
|
||||
def info(self, msg):
|
||||
''' Utility method for writing output to stdout.'''
|
||||
print msg
|
||||
print(msg)
|
||||
sys.stdout.flush()
|
||||
|
||||
def warn(self, msg):
|
||||
''' Utility method for writing output to stderr. '''
|
||||
print >> sys.stderr, "XXX %s:" % self.node.routerid, msg
|
||||
sys.stderr.write("XXX %s:" % self.node.routerid, msg)
|
||||
sys.stderr.flush()
|
||||
|
||||
def run(self):
|
||||
|
|
|
@ -114,12 +114,12 @@ class Cmd(object):
|
|||
|
||||
def info(self, msg):
|
||||
""" Utility method for writing output to stdout."""
|
||||
print msg
|
||||
print(msg)
|
||||
sys.stdout.flush()
|
||||
|
||||
def warn(self, msg):
|
||||
""" Utility method for writing output to stderr. """
|
||||
print >> sys.stderr, "XXX %s:" % self.node.name, msg
|
||||
sys.stderr.write("XXX %s:" % self.node.name, msg)
|
||||
sys.stderr.flush()
|
||||
|
||||
def run(self):
|
||||
|
@ -358,13 +358,13 @@ class Experiment(object):
|
|||
|
||||
def info(self, msg):
|
||||
""" Utility method for writing output to stdout. """
|
||||
print msg
|
||||
print(msg)
|
||||
sys.stdout.flush()
|
||||
self.log(msg)
|
||||
|
||||
def warn(self, msg):
|
||||
""" Utility method for writing output to stderr. """
|
||||
print >> sys.stderr, msg
|
||||
sys.stderr.write(msg)
|
||||
sys.stderr.flush()
|
||||
self.log(msg)
|
||||
|
||||
|
@ -394,7 +394,7 @@ class Experiment(object):
|
|||
""" Write to the log file, if any. """
|
||||
if not self.logfp:
|
||||
return
|
||||
print >> self.logfp, msg
|
||||
self.logfp.write(msg)
|
||||
|
||||
def reset(self):
|
||||
""" Prepare for another experiment run.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue