2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation;
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 # Example of how to run this experiment (replace with your information):
23 # python examples/planetlab/select_nodes.py -s <pl-slice> -u <pl-user> -p <pl-password> -k <pl-ssh-key> -c <country> -o <operating-system> -n <node-count>
26 from nepi.execution.ec import ExperimentController
28 from optparse import OptionParser
31 usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
32 "-k <pl-ssh-key> -c <country> -o <operating-system> -n <node-count> ")
34 parser = OptionParser(usage = usage)
35 parser.add_option("-s", "--pl-slice", dest="pl_slice",
36 help="PlanetLab slicename", type="str")
37 parser.add_option("-u", "--pl-user", dest="pl_user",
38 help="PlanetLab web username", type="str")
39 parser.add_option("-p", "--pl-password", dest="pl_password",
40 help="PlanetLab web password", type="str")
41 parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
42 help="Path to private SSH key associated with the PL account",
44 parser.add_option("-c", "--country", dest="country",
45 help="Country for the PL hosts",
47 parser.add_option("-o", "--os", dest="os",
48 help="Operating system for the PL hosts",
50 parser.add_option("-n", "--node-count", dest="node_count",
51 help="Number of PL hosts to provision",
55 (options, args) = parser.parse_args()
57 pl_slice = options.pl_slice
58 pl_ssh_key = options.pl_ssh_key
59 pl_user = options.pl_user
60 pl_password = options.pl_password
61 country = options.country
63 node_count = options.node_count
65 def add_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password, country, os):
66 node = ec.register_resource("planetlab::Node")
67 ec.set(node, "username", pl_slice)
68 ec.set(node, "identity", pl_ssh_key)
69 ec.set(node, "pluser", pl_user)
70 ec.set(node, "plpassword", pl_password)
73 ec.set(node, "country", country)
75 ec.set(node, "operatingSystem", os)
77 ec.set(node, "cleanExperiment", True)
78 ec.set(node, "cleanProcesses", True)
82 ## Create the experiment controller
83 ec = ExperimentController(exp_id="host_select")
87 for i in xrange(node_count):
88 node = add_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password, country, os)
93 ec.wait_deployed(nodes)
95 print "SELECTED HOSTS"
98 print ec.get(node, "hostname")