from nepi.execution.ec import ExperimentController
+from optparse import OptionParser, SUPPRESS_HELP
import os
-ssh_key = ####### <<< ASSING the absolute path to the private SSH key to login into the remote host >>>
-ssh_user = ####### <<< ASSING the SSH username >>>
-
-results_dir = "/tmp/demo_CCN_results"
+usage = ("usage: %prog -a <hostanme1> -b <hostname2> -u <username> -i <ssh-key>")
+
+parser = OptionParser(usage = usage)
+parser.add_option("-a", "--hostname1", dest="hostname1",
+ help="Remote host 1", type="str")
+parser.add_option("-b", "--hostname2", dest="hostname2",
+ help="Remote host 2", type="str")
+parser.add_option("-u", "--username", dest="username",
+ help="Username to SSH to remote host", type="str")
+parser.add_option("-i", "--ssh-key", dest="ssh_key",
+ help="Path to private SSH key to be used for connection",
+ type="str")
+(options, args) = parser.parse_args()
+
+hostname1 = options.hostname1
+hostname2 = options.hostname2
+username = options.username
+ssh_key = options.ssh_key
## Create the experiment controller
-ec = ExperimentController(exp_id = "demo_CCN", local_dir = results_dir)
+ec = ExperimentController(exp_id = "ccn_simple_transfer")
## Register node 1
node1 = ec.register_resource("LinuxNode")
# Set the hostname of the first node to use for the experiment
-hostname1 = "peeramidion.irisa.fr" ##### <<< ASSIGN the hostname of a host you have SSSH access to >>>
ec.set(node1, "hostname", hostname1)
# username should be your SSH user
-ec.set(node1, "username", ssh_user)
+ec.set(node1, "username", username)
# Absolute path to the SSH private key
ec.set(node1, "identity", ssh_key)
# Clean all files, results, etc, from previous experiments wit the same exp_id
## Register node 2
node2 = ec.register_resource("LinuxNode")
# Set the hostname of the first node to use for the experiment
-hostname2 = "planetlab2.upc.es" ##### <<< ASSIGN the hostname of a host you have SSSH access to >>>
ec.set(node2, "hostname", hostname2)
# username should be your SSH user
-ec.set(node2, "username", ssh_user)
+ec.set(node2, "username", username)
# Absolute path to the SSH private key
ec.set(node2, "identity", ssh_key)
# Clean all files, results, etc, from previous experiments wit the same exp_id
ec.set(col2, "subDir", hostname2)
ec.register_connection(col2, ccnd2)
+print "Results stored at", ec.exp_dir
+
## Deploy all resources
ec.deploy()
# Wait until the ccncat is finished
ec.wait_finished([app])
-## CCND logs will be collected to the results_dir upon shutdown.
-## We can aldo get the content of the logs now:
-#print "LOG2", ec.trace(ccnd1, "stderr")
-#print "LOG 1", ec.trace(ccnd2, "stderr")
-
ec.shutdown()
#
#
# content ccncat
-# PL host Linux host
+# Linux host Linux host
# 0 ------- Internet ------ 0
#
# Example of how to run this experiment (replace with your credentials):
#
# $ cd <path-to-nepi>
-# $ PYTHONPATH=$PYTHONPATH:~/repos/nepi/src python examples/linux/file_transfer.py -u inria_nepi -i ~/.ssh/id_rsa_planetlab -a planetlab1.u-strasbg.fr -b planetlab1.utt.fr
-
+# python examples/linux/netcat_file_transfer.py -a <hostanme1> -b <hostname2> -u <username> -i <ssh-key>
from nepi.execution.ec import ExperimentController
from nepi.execution.resource import ResourceAction, ResourceState
ssh_key = options.ssh_key
## Create the experiment controller
-ec = ExperimentController(exp_id = "file_transfer")
+ec = ExperimentController(exp_id = "nc_file_transfer")
## Register node 1
node1 = ec.register_resource("LinuxNode")
from nepi.execution.ec import ExperimentController
+from optparse import OptionParser, SUPPRESS_HELP
+import os
+
+usage = ("usage: %prog -a <hostanme> -u <username> -i <ssh-key>")
+
+parser = OptionParser(usage = usage)
+parser.add_option("-a", "--hostname", dest="hostname",
+ help="Remote host", type="str")
+parser.add_option("-u", "--username", dest="username",
+ help="Username to SSH to remote host", type="str")
+parser.add_option("-i", "--ssh-key", dest="ssh_key",
+ help="Path to private SSH key to be used for connection",
+ type="str")
+(options, args) = parser.parse_args()
+
+hostname = options.hostname
+username = options.username
+ssh_key = options.ssh_key
+
ec = ExperimentController(exp_id = "ping-exp")
-hostname = ## Add a string with the target hostname
-username = ## Add a string with the username to SSH hostname
-
node = ec.register_resource("LinuxNode")
ec.set(node, "hostname", hostname)
ec.set(node, "username", username)
+ec.set(node, "identity", ssh_key)
ec.set(node, "cleanHome", True)
ec.set(node, "cleanProcesses", True)
app = ec.register_resource("LinuxApplication")
-ec.set(app, "command", "ping -c3 www.google.com")
+ec.set(app, "command", "ping -c3 nepi.inria.fr")
ec.register_connection(app, node)
ec.deploy()
print ec.trace(app, "stdout")
ec.shutdown()
+
--- /dev/null
+from nepi.execution.ec import ExperimentController
+
+from optparse import OptionParser, SUPPRESS_HELP
+import os
+
+usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
+ "-k <pl-ssh-key> -c <country> -o <operating-system> -n <node-count> ")
+
+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")
+parser.add_option("-c", "--country", dest="country",
+ help="Country for the PL hosts",
+ type="str")
+parser.add_option("-o", "--os", dest="os",
+ help="Operating system for the PL hosts",
+ type="str")
+parser.add_option("-n", "--node-count", dest="node_count",
+ help="Number of PL hosts to provision",
+ default = 2,
+ type="int")
+
+(options, args) = parser.parse_args()
+
+pl_slice = options.pl_slice
+pl_ssh_key = options.pl_ssh_key
+pl_user = options.pl_user
+pl_password = options.pl_password
+country = options.country
+os = options.os
+node_count = options.node_count
+
+def add_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password, country, os):
+ node = ec.register_resource("PlanetlabNode")
+ ec.set(node, "username", pl_slice)
+ ec.set(node, "identity", pl_ssh_key)
+ ec.set(node, "pluser", pl_user)
+ ec.set(node, "plpassword", pl_password)
+
+ if country:
+ ec.set(node, "country", country)
+ if os:
+ ec.set(node, "operatingSystem", os)
+
+ ec.set(node, "cleanHome", True)
+ ec.set(node, "cleanProcesses", True)
+
+ return node
+
+## Create the experiment controller
+ec = ExperimentController(exp_id="host_select")
+
+nodes = []
+
+for i in xrange(node_count):
+ node = add_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password, country, os)
+ nodes.append(node)
+
+ec.deploy()
+
+ec.wait_deployed(nodes)
+
+print "SELECTED HOSTS"
+
+for node in nodes:
+ print ec.get(node, "hostname")
+
+ec.shutdown()
+
+