omf bootstrap
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 18 Jan 2015 19:13:50 +0000 (20:13 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 18 Jan 2015 19:13:50 +0000 (20:13 +0100)
examples/omf/nitos_testbed_bootstrap.py [moved from examples/linux/nitos_testbed_bootstrap.py with 63% similarity]

similarity index 63%
rename from examples/linux/nitos_testbed_bootstrap.py
rename to examples/omf/nitos_testbed_bootstrap.py
index ad44d12..34d2e3f 100644 (file)
 # 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 <list-of-nitos-hosts> -u <nitos-username> -i <ssh-key> -g <nitos-gateway> -U <nitos-gateway-username>\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 optparse import OptionParser, SUPPRESS_HELP\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
@@ -53,34 +55,64 @@ parser.add_option("-i", "--ssh-key", dest="ssh_key",
         type="str")\r
 (options, args) = parser.parse_args()\r
 \r
-hosts = options.hosts.split(" ")\r
+hosts = options.hosts\r
 username = options.username\r
 gateway = options.gateway\r
 gateway_username = options.gateway_username\r
-ssh_key = options.ssh_key\r
+identity = options.ssh_key\r
 \r
 apps = []\r
 \r
-ec = ExperimentController(exp_id="ath5k")\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", hostname)\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
-\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()\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
+    print ec.trace(app, "stdout")\r
 \r
+ec.shutdown()\r
 \r