git://git.onelab.eu
/
nepi.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tweaked Makefile to use either setup or twine to upload stuff onto pypi
[nepi.git]
/
examples
/
linux
/
netcat_file_transfer.py
diff --git
a/examples/linux/netcat_file_transfer.py
b/examples/linux/netcat_file_transfer.py
index
e2047d1
..
6d43764
100644
(file)
--- a/
examples/linux/netcat_file_transfer.py
+++ b/
examples/linux/netcat_file_transfer.py
@@
-4,9
+4,8
@@
# Copyright (C) 2013 INRIA
#
# This program is free software: you can redistribute it and/or modify
# Copyright (C) 2013 INRIA
#
# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-25,6
+24,8
@@
# $ cd <path-to-nepi>
# python examples/linux/netcat_file_transfer.py -a <hostname1> -b <hostname2> -u <username> -i <ssh-key>
# $ cd <path-to-nepi>
# python examples/linux/netcat_file_transfer.py -a <hostname1> -b <hostname2> -u <username> -i <ssh-key>
+from __future__ import print_function
+
from nepi.execution.ec import ExperimentController
from nepi.execution.resource import ResourceAction, ResourceState
from nepi.execution.ec import ExperimentController
from nepi.execution.resource import ResourceAction, ResourceState
@@
-54,7
+55,7
@@
ssh_key = options.ssh_key
ec = ExperimentController(exp_id = "nc_file_transfer")
## Register node 1
ec = ExperimentController(exp_id = "nc_file_transfer")
## Register node 1
-node1 = ec.register_resource("
Linux
Node")
+node1 = ec.register_resource("
linux::
Node")
# Set the hostname of the first node to use for the experiment
ec.set(node1, "hostname", hostname1)
# username should be your SSH user
# Set the hostname of the first node to use for the experiment
ec.set(node1, "hostname", hostname1)
# username should be your SSH user
@@
-67,7
+68,7
@@
ec.set(node1, "cleanExperiment", True)
ec.set(node1, "cleanProcesses", True)
## Register node 2
ec.set(node1, "cleanProcesses", True)
## Register node 2
-node2 = ec.register_resource("
Linux
Node")
+node2 = ec.register_resource("
linux::
Node")
# Set the hostname of the first node to use for the experiment
ec.set(node2, "hostname", hostname2)
# username should be your SSH user
# Set the hostname of the first node to use for the experiment
ec.set(node2, "hostname", hostname2)
# username should be your SSH user
@@
-88,7
+89,7
@@
local_path_to_video = os.path.join(
command = "cat ${SHARE}/%s | pv -fbt 2> bw.txt | nc %s 1234" % (
video, hostname2 )
command = "cat ${SHARE}/%s | pv -fbt 2> bw.txt | nc %s 1234" % (
video, hostname2 )
-server = ec.register_resource("
Linux
Application")
+server = ec.register_resource("
linux::
Application")
ec.set(server, "depends", "pv nc tcpdump")
ec.set(server, "files", local_path_to_video)
ec.set(server, "command", command)
ec.set(server, "depends", "pv nc tcpdump")
ec.set(server, "files", local_path_to_video)
ec.set(server, "command", command)
@@
-100,7
+101,7
@@
ec.register_connection(server, node1)
# if not nc in the client side close the socket suddently if runned in background
command = "nc -dl 1234 > %s" % video
# if not nc in the client side close the socket suddently if runned in background
command = "nc -dl 1234 > %s" % video
-client = ec.register_resource("
Linux
Application")
+client = ec.register_resource("
linux::
Application")
ec.set(client, "depends", "nc")
ec.set(client, "command", command)
ec.register_connection(client, node2)
ec.set(client, "depends", "nc")
ec.set(client, "command", command)
ec.register_connection(client, node2)
@@
-108,7
+109,7
@@
ec.register_connection(client, node2)
# Register a tcpdump in the server node to monitor the file transfer
command = "tcpdump -ni eth0 -w file_transfer.pcap -s0 port 1234 2>&1"
# Register a tcpdump in the server node to monitor the file transfer
command = "tcpdump -ni eth0 -w file_transfer.pcap -s0 port 1234 2>&1"
-capture = ec.register_resource("
Linux
Application")
+capture = ec.register_resource("
linux::
Application")
ec.set(capture, "depends", "tcpdump")
ec.set(capture, "command", command)
ec.set(capture, "sudo", True)
ec.set(capture, "depends", "tcpdump")
ec.set(capture, "command", command)
ec.set(capture, "sudo", True)
@@
-130,14
+131,12
@@
bw = ec.trace(server, "bw.txt")
pcap = ec.trace(capture, "file_transfer.pcap")
# Choose a directory to store the traces, example f = open("/home/<user>/bw.txt", "w")
pcap = ec.trace(capture, "file_transfer.pcap")
# Choose a directory to store the traces, example f = open("/home/<user>/bw.txt", "w")
-f = open("bw.txt", "w")
-f.write(bw)
-f.close()
-f = open("video_transfer.pcap", "w")
-f.write(pcap)
-f.close()
+with open("bw.txt", "w") as f:
+ f.write(bw)
+with open("video_transfer.pcap", "w") as f:
+ f.write(pcap)
ec.shutdown()
ec.shutdown()
-print
"Total bytes transfered saved to bw.txt..."
+print
("Total bytes transfered saved to bw.txt...")