3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 # This very simple experiment will ssh in a linux box, and from there
21 # issue a ping command towards a landmark (default faraday.inria.fr)
23 # $ ping.py -u root mybox.domain.com
25 # would do the equivalent of
26 # ssh root@mybox.domain.com ping -c3 faraday.inria.fr
28 # If nepi is not installed in your system, and you only have a git clone
29 # you might wish to do instead
31 # $ cd <path-to-nepi>/src
32 # $ python ../examples/linux/ping.py -u root mybox.domain.com
34 # let's be ready for python3
35 from __future__ import print_function
38 from argparse import ArgumentParser
40 from nepi.execution.ec import ExperimentController
43 default_landmark = "faraday.inria.fr"
45 parser = ArgumentParser()
46 parser.add_argument("-u", "--username", dest="username",
47 help="Username to SSH to remote host")
48 parser.add_argument("-i", "--ssh-key", dest="ssh_key",
49 help="Path to private SSH key to be used for connection")
50 parser.add_argument("-l", "--landmark", dest='landmark', default=default_landmark,
51 help="Set pings destination, default={}".format(default_landmark))
53 parser.add_argument("hostname", type=str)
55 args = parser.parse_args()
57 hostname = args.hostname
58 username = args.username
59 ssh_key = args.ssh_key
60 landmark = args.landmark
62 ec = ExperimentController(exp_id = "ping-exp")
64 node = ec.register_resource("linux::Node")
65 ec.set(node, "hostname", hostname)
66 ec.set(node, "username", username)
67 ec.set(node, "identity", ssh_key)
68 ec.set(node, "cleanExperiment", True)
69 ec.set(node, "cleanProcesses", True)
71 app = ec.register_resource("linux::Application")
72 ec.set(app, "command", "ping -c3 {}".format(landmark))
73 ec.register_connection(app, node)
79 print(ec.trace(app, "stdout"))