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 as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
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.
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/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
21 # Example of how to run this experiment (replace with your information):
24 # 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>
27 from nepi.execution.ec import ExperimentController
29 from optparse import OptionParser
32 usage = ("usage: %prog -s <pl-slice> -u <pl-user> -p <pl-password> "
33 "-k <pl-ssh-key> -c <country> -o <operating-system> -n <node-count> ")
35 parser = OptionParser(usage = usage)
36 parser.add_option("-s", "--pl-slice", dest="pl_slice",
37 help="PlanetLab slicename", type="str")
38 parser.add_option("-u", "--pl-user", dest="pl_user",
39 help="PlanetLab web username", type="str")
40 parser.add_option("-p", "--pl-password", dest="pl_password",
41 help="PlanetLab web password", type="str")
42 parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
43 help="Path to private SSH key associated with the PL account",
45 parser.add_option("-c", "--country", dest="country",
46 help="Country for the PL hosts",
48 parser.add_option("-o", "--os", dest="os",
49 help="Operating system for the PL hosts",
51 parser.add_option("-n", "--node-count", dest="node_count",
52 help="Number of PL hosts to provision",
56 (options, args) = parser.parse_args()
58 pl_slice = options.pl_slice
59 pl_ssh_key = options.pl_ssh_key
60 pl_user = options.pl_user
61 pl_password = options.pl_password
62 country = options.country
64 node_count = options.node_count
66 def add_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password, country, os):
67 node = ec.register_resource("planetlab::Node")
68 ec.set(node, "username", pl_slice)
69 ec.set(node, "identity", pl_ssh_key)
70 ec.set(node, "pluser", pl_user)
71 ec.set(node, "plpassword", pl_password)
74 ec.set(node, "country", country)
76 ec.set(node, "operatingSystem", os)
78 ec.set(node, "cleanExperiment", True)
79 ec.set(node, "cleanProcesses", True)
83 ## Create the experiment controller
84 ec = ExperimentController(exp_id="host_select")
88 for i in xrange(node_count):
89 node = add_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password, country, os)
94 ec.wait_deployed(nodes)
96 print "SELECTED HOSTS"
99 print ec.get(node, "hostname")