Adding nitos_testbed_bootstrap.py
[nepi.git] / examples / linux / nitos_testbed_bootstrap.py
1 #\r
2 #    NEPI, a framework to manage network experiments\r
3 #    Copyright (C) 2014 INRIA\r
4 #\r
5 #    This program is free software: you can redistribute it and/or modify\r
6 #    it under the terms of the GNU General Public License as published by\r
7 #    the Free Software Foundation, either version 3 of the License, or\r
8 #    (at your option) any later version.\r
9 #\r
10 #    This program is distributed in the hope that it will be useful,\r
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 #    GNU General Public License for more details.\r
14 #\r
15 #    You should have received a copy of the GNU General Public License\r
16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
17 #\r
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>\r
19 #         Maksym Gabielkov <maksym.gabielkovc@inria.fr>\r
20 #\r
21 \r
22 ## This is a maintenance script used to bootstrap the nodes from\r
23 ## Nitos testbed (NITLab) before running a OMF experiment using\r
24 ## Nitos nodes. This fixes the problem of Resource Controller \r
25 ## misbehaving by restarting it and it also loads the ath5k driver.\r
26 \r
27 # Example of how to run this experiment (replace with your information):\r
28 #\r
29 # $ cd <path-to-nepi>\r
30 # python examples/linux/nitos_testbed_bootstrap.py -H <list-of-nitos-hosts> -u <nitos-username> -i <ssh-key> -g <nitos-gateway> -U <nitos-gateway-username>\r
31 #\r
32 \r
33 from nepi.execution.ec import ExperimentController\r
34 from optparse import OptionParser, SUPPRESS_HELP\r
35 import os\r
36 \r
37 usage = ("usage: %prog -H <list-of-nitos-hosts> -u <nitos-username> -i <ssh-key> -g <nitos-gateway> -U <nitos-gateway-username>")\r
38 \r
39 parser = OptionParser(usage = usage)\r
40 parser.add_option("-H", "--hosts", dest="hosts", \r
41         help="Space separated list of hosts", type="str")\r
42 parser.add_option("-u", "--username", dest="username", \r
43         help="Username for the nitos hosts (usually root)", \r
44         type="str", default="root" )\r
45 parser.add_option("-g", "--gateway", dest="gateway", \r
46         help="Nitos gateway hostname", \r
47         type="str", default="nitlab.inf.uth.gr")\r
48 parser.add_option("-U", "--gateway-user", dest="gateway_username", \r
49         help="Nitos gateway username", \r
50         type="str", default="nitlab.inf.uth.gr")\r
51 parser.add_option("-i", "--ssh-key", dest="ssh_key", \r
52         help="Path to private SSH key to be used for connection", \r
53         type="str")\r
54 (options, args) = parser.parse_args()\r
55 \r
56 hosts = options.hosts.split(" ")\r
57 username = options.username\r
58 gateway = options.gateway\r
59 gateway_username = options.gateway_username\r
60 ssh_key = options.ssh_key\r
61 \r
62 apps = []\r
63 \r
64 ec = ExperimentController(exp_id="ath5k")\r
65 \r
66 for hostname in hosts:\r
67    node = ec.register_resource("LinuxNode")\r
68    ec.set(node, "username", username)\r
69    ec.set(node, "hostname", hostname)\r
70    ec.set(node, "gateway", gateway )\r
71    ec.set(node, "gatewayUser", gateway_username)\r
72    ec.set(node, "cleanExperiment", True)\r
73 \r
74    app = ec.register_resource("LinuxApplication")\r
75    ec.set(app, "command", "modprobe ath5k && ip a | grep wlan0 && service omf_rc restart")\r
76    ec.register_connection(app, node)\r
77    \r
78    apps.append(app)\r
79 \r
80 ec.deploy()\r
81 ec.wait_finished(apps)\r
82 \r
83 for app in apps:\r
84    print ec.trace(app, "stdout") \r
85 \r
86 \r