Planetlab examples
[nepi.git] / examples / planetlab / ping.py
similarity index 52%
rename from examples/planetlab/ping_experiment.py
rename to examples/planetlab/ping.py
index 4a693fd..e36ba61 100644 (file)
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
+#         Alina Quereilhac <alina.quereilhac@inria.fr>
+#
+
+# Example of how to run this experiment (replace with your information):
+#
+# $ cd <path-to-nepi>
+# python examples/planetlab/ping.py -s <pl-slice> -u <pl-user> -p <pl-password> -k <pl-ssh-key>  
+
 
 from nepi.execution.ec import ExperimentController
-from nepi.execution.resource import ResourceAction, ResourceState
 
+from optparse import OptionParser
 import os
 
-exp_id = "ping_exp"
+usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
+     "-k <pl-ssh-key>")
+
+parser = OptionParser(usage = usage)
+parser.add_option("-s", "--pl-slice", dest="pl_slice",
+        help="PlanetLab slicename", type="str")
+parser.add_option("-u", "--pl-user", dest="pl_user",
+        help="PlanetLab web username", type="str")
+parser.add_option("-p", "--pl-password", dest="pl_password",
+        help="PlanetLab web password", type="str")
+parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
+        help="Path to private SSH key associated with the PL account",
+        type="str")
 
-# Create the entity Experiment Controller:
-ec = ExperimentController(exp_id)
+(options, args) = parser.parse_args()
 
-# Register the nodes resources:
+pl_slice = options.pl_slice
+pl_ssh_key = options.pl_ssh_key
+pl_user = options.pl_user
+pl_password = options.pl_password
+
+## Create the experiment controller
+ec = ExperimentController(exp_id = "pl_ping")
+
+# Register a Planetlab Node with no restrictions, it can be any node
+node = ec.register_resource("PlanetlabNode")
 
 # The username in this case is the slice name, the one to use for login in 
 # via ssh into PlanetLab nodes. Replace with your own slice name.
-username = "inria_sfatest"
+ec.set(node, "username", pl_slice)
+ec.set(node, "identity", pl_ssh_key)
 
 # The pluser and plpassword are the ones used to login in the PlanetLab web 
 # site. Replace with your own user and password account information.
-pl_user = "lucia.guevgeozian_odizzio@inria.fr"
-pl_password =  os.environ.get("PL_PASS")
-
-# Define a Planetlab Node with no restriction, it can be any node
-node = ec.register_resource('PlanetlabNode')
-ec.set(node, "username", username)
 ec.set(node, "pluser", pl_user)
 ec.set(node, "plpassword", pl_password)
+
+# Remove previous results
 ec.set(node, "cleanHome", True)
 ec.set(node, "cleanProcesses", True)
 
 # Define a ping application
-app = ec.register_resource('LinuxApplication')
-ec.set(app, 'command', 'ping -c5 google.com > ping_google.txt')
+app = ec.register_resource("LinuxApplication")
+ec.set(app, "command", "ping -c3 nepi.inria.fr")
 
 # Connect the application to the node
 ec.register_connection(node, app)
@@ -60,14 +85,9 @@ ec.deploy()
 # Wait until the application is finish to retrive the trace:
 ec.wait_finished(app)
 
-trace = ec.trace(app, 'ping_google.txt')
+trace = ec.trace(app, "stdout")
 
-# Choose a directory to store the traces locally, change to a convenient path for you:
-directory = "examples/planetlab/"
-trace_file = directory + "ping_google.txt"
-f = open(trace_file, "w")
-f.write(trace)
-f.close()
+print "PING outout ", trace
 
 # Do the experiment controller shutdown:
 ec.shutdown()