Planetlab examples
[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 as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
20 #         Alina Quereilhac <alina.quereilhac@inria.fr>
21 #
22
23 # Example of how to run this experiment (replace with your information):
24 #
25 # $ cd <path-to-nepi>
26 # python examples/planetlab/ping.py -s <pl-slice> -u <pl-user> -p <pl-password> -k <pl-ssh-key>  
27
28
29 from nepi.execution.ec import ExperimentController
30
31 from optparse import OptionParser
32 import os
33
34 usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
35      "-k <pl-ssh-key>")
36
37 parser = OptionParser(usage = usage)
38 parser.add_option("-s", "--pl-slice", dest="pl_slice",
39         help="PlanetLab slicename", type="str")
40 parser.add_option("-u", "--pl-user", dest="pl_user",
41         help="PlanetLab web username", type="str")
42 parser.add_option("-p", "--pl-password", dest="pl_password",
43         help="PlanetLab web password", type="str")
44 parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
45         help="Path to private SSH key associated with the PL account",
46         type="str")
47
48 (options, args) = parser.parse_args()
49
50 pl_slice = options.pl_slice
51 pl_ssh_key = options.pl_ssh_key
52 pl_user = options.pl_user
53 pl_password = options.pl_password
54
55 ## Create the experiment controller
56 ec = ExperimentController(exp_id = "pl_ping")
57
58 # Register a Planetlab Node with no restrictions, it can be any node
59 node = ec.register_resource("PlanetlabNode")
60
61 # The username in this case is the slice name, the one to use for login in 
62 # via ssh into PlanetLab nodes. Replace with your own slice name.
63 ec.set(node, "username", pl_slice)
64 ec.set(node, "identity", pl_ssh_key)
65
66 # The pluser and plpassword are the ones used to login in the PlanetLab web 
67 # site. Replace with your own user and password account information.
68 ec.set(node, "pluser", pl_user)
69 ec.set(node, "plpassword", pl_password)
70
71 # Remove previous results
72 ec.set(node, "cleanHome", True)
73 ec.set(node, "cleanProcesses", True)
74
75 # Define a ping application
76 app = ec.register_resource("LinuxApplication")
77 ec.set(app, "command", "ping -c3 nepi.inria.fr")
78
79 # Connect the application to the node
80 ec.register_connection(node, app)
81     
82 # Deploy the experiment:
83 ec.deploy()
84
85 # Wait until the application is finish to retrive the trace:
86 ec.wait_finished(app)
87
88 trace = ec.trace(app, "stdout")
89
90 print "PING outout ", trace
91
92 # Do the experiment controller shutdown:
93 ec.shutdown()
94
95 # END