omf bootstrap
[nepi.git] / examples / omf / nitos_testbed_bootstrap.py
diff --git a/examples/omf/nitos_testbed_bootstrap.py b/examples/omf/nitos_testbed_bootstrap.py
new file mode 100644 (file)
index 0000000..34d2e3f
--- /dev/null
@@ -0,0 +1,118 @@
+#\r
+#    NEPI, a framework to manage network experiments\r
+#    Copyright (C) 2014 INRIA\r
+#\r
+#    This program is free software: you can redistribute it and/or modify\r
+#    it under the terms of the GNU General Public License as published by\r
+#    the Free Software Foundation, either version 3 of the License, or\r
+#    (at your option) any later version.\r
+#\r
+#    This program is distributed in the hope that it will be useful,\r
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+#    GNU General Public License for more details.\r
+#\r
+#    You should have received a copy of the GNU General Public License\r
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+#\r
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>\r
+#         Maksym Gabielkov <maksym.gabielkovc@inria.fr>\r
+#\r
+\r
+## This is a maintenance script used to bootstrap the nodes from\r
+## Nitos testbed (NITLab) before running a OMF experiment using\r
+## Nitos nodes. This fixes the problem of Resource Controller \r
+## misbehaving by restarting it and it also loads the ath5k driver.\r
+\r
+# Example of how to run this experiment (replace with your information):\r
+#\r
+# $ cd <path-to-nepi>\r
+# python examples/linux/nitos_testbed_bootstrap.py -H <omf.nitos.node0XX,omf.nitos.node0ZZ,..> -u <nitos-username> -i <ssh-key> -g <nitos-gateway> -U <nitos-gateway-username>\r
+#\r
+\r
+from nepi.execution.ec import ExperimentController\r
+from nepi.execution.resource import ResourceAction, ResourceState\r
+\r
+from optparse import OptionParser\r
+import os\r
+\r
+usage = ("usage: %prog -H <list-of-nitos-hosts> -u <nitos-username> -i <ssh-key> -g <nitos-gateway> -U <nitos-gateway-username>")\r
+\r
+parser = OptionParser(usage = usage)\r
+parser.add_option("-H", "--hosts", dest="hosts", \r
+        help="Space separated list of hosts", type="str")\r
+parser.add_option("-u", "--username", dest="username", \r
+        help="Username for the nitos hosts (usually root)", \r
+        type="str", default="root" )\r
+parser.add_option("-g", "--gateway", dest="gateway", \r
+        help="Nitos gateway hostname", \r
+        type="str", default="nitlab.inf.uth.gr")\r
+parser.add_option("-U", "--gateway-user", dest="gateway_username", \r
+        help="Nitos gateway username", \r
+        type="str", default="nitlab.inf.uth.gr")\r
+parser.add_option("-i", "--ssh-key", dest="ssh_key", \r
+        help="Path to private SSH key to be used for connection", \r
+        type="str")\r
+(options, args) = parser.parse_args()\r
+\r
+hosts = options.hosts\r
+username = options.username\r
+gateway = options.gateway\r
+gateway_username = options.gateway_username\r
+identity = options.ssh_key\r
+\r
+apps = []\r
+\r
+ec = ExperimentController(exp_id="nitos_bootstrap")\r
+\r
+gw_node = ec.register_resource("linux::Node")\r
+ec.set(gw_node, "username", gateway_username)\r
+ec.set(gw_node, "hostname", gateway)\r
+ec.set(gw_node, "identity", identity)\r
+ec.set(gw_node, "cleanExperiment", True)\r
+\r
+load_cmd = "omf load -i nepi_OMF6_VLC_baseline_grid.ndz -t %s" % hosts \r
+load_app = ec.register_resource("linux::Application")\r
+ec.set(load_app, "command", load_cmd)\r
+ec.register_connection(load_app, gw_node)\r
+\r
+reboot_cmd = "omf tell -a on -t %s" % hosts \r
+reboot_app = ec.register_resource("linux::Application")\r
+ec.set(reboot_app, "command", reboot_cmd)\r
+ec.register_connection(reboot_app, gw_node)\r
+\r
+ec.register_condition(reboot_app, ResourceAction.START, load_app, \r
+            ResourceState.STOPPED, time="20s") \r
+\r
+hosts = hosts.split(",")\r
+\r
+for hostname in hosts:\r
+    host = hostname.split(".")[-1]\r
+    node = ec.register_resource("linux::Node")\r
+    ec.set(node, "username", username)\r
+    ec.set(node, "hostname", host)\r
+    ec.set(node, "identity", identity)\r
+    ec.set(node, "gateway", gateway)\r
+    ec.set(node, "gatewayUser", gateway_username)\r
+    ec.set(node, "cleanExperiment", True)\r
+    ec.register_condition(node, ResourceAction.DEPLOY, reboot_app, \r
+            ResourceState.STOPPED, time="30s") \r
\r
+    app = ec.register_resource("linux::Application")\r
+    ec.set(app, "command", "modprobe ath5k && ip a | grep wlan0 && service omf_rc restart")\r
+    ec.register_connection(app, node)\r
+   \r
+    apps.append(app)\r
+\r
+ec.deploy(wait_all_ready=False)\r
+\r
+ec.wait_finished(apps)\r
+\r
+print ec.trace(load_app, "stdout")\r
+print ec.trace(reboot_app, "stdout")\r
+\r
+for app in apps:\r
+    print ec.trace(app, "stdout")\r
+\r
+ec.shutdown()\r
+\r