c48127834d51d68d556ed38f126735069e131d45
[nepi.git] / examples / planetlab / ping.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
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;
9 #
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.
14 #
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/>.
17 #
18 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
19 #         Alina Quereilhac <alina.quereilhac@inria.fr>
20 #
21
22 # Example of how to run this experiment (replace with your information):
23 #
24 # $ cd <path-to-nepi>
25 # python examples/planetlab/ping.py -s <pl-slice> -u <pl-user> -p <pl-password> -k <pl-ssh-key>  
26
27
28 from nepi.execution.ec import ExperimentController
29
30 from optparse import OptionParser
31 import os
32
33 usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
34      "-k <pl-ssh-key>")
35
36 parser = OptionParser(usage = usage)
37 parser.add_option("-s", "--pl-slice", dest="pl_slice",
38         help="PlanetLab slicename", type="str")
39 parser.add_option("-u", "--pl-user", dest="pl_user",
40         help="PlanetLab web username", type="str")
41 parser.add_option("-p", "--pl-password", dest="pl_password",
42         help="PlanetLab web password", type="str")
43 parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
44         help="Path to private SSH key associated with the PL account",
45         type="str")
46
47 (options, args) = parser.parse_args()
48
49 pl_slice = options.pl_slice
50 pl_ssh_key = options.pl_ssh_key
51 pl_user = options.pl_user
52 pl_password = options.pl_password
53
54 ## Create the experiment controller
55 ec = ExperimentController(exp_id = "pl_ping")
56
57 # Register a Planetlab Node with no restrictions, it can be any node
58 node = ec.register_resource("planetlab::Node")
59
60 # The username in this case is the slice name, the one to use for login in 
61 # via ssh into PlanetLab nodes. Replace with your own slice name.
62 ec.set(node, "username", pl_slice)
63 ec.set(node, "identity", pl_ssh_key)
64
65 # The pluser and plpassword are the ones used to login in the PlanetLab web 
66 # site. Replace with your own user and password account information.
67 ec.set(node, "pluser", pl_user)
68 ec.set(node, "plpassword", pl_password)
69
70 # Remove previous results
71 ec.set(node, "cleanExperiment", True)
72 ec.set(node, "cleanProcesses", True)
73
74 # Define a ping application
75 app = ec.register_resource("linux::Application")
76 ec.set(app, "command", "ping -c3 nepi.inria.fr")
77
78 # Connect the application to the node
79 ec.register_connection(node, app)
80     
81 # Deploy the experiment:
82 ec.deploy()
83
84 # Wait until the application is finish to retrive the trace:
85 ec.wait_finished(app)
86
87 trace = ec.trace(app, "stdout")
88
89 print "PING outout ", trace
90
91 # Do the experiment controller shutdown
92 ec.shutdown()
93
94 # END