424536b35423a0fc7d16181afbf7062cea30ace6
[nepi.git] / examples / linux / hello_world.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License version 2 as
8 #    published by the Free Software Foundation;
9 #
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.
14 #
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/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 # Example of how to run this experiment (replace with your information):
21 #
22 # $ cd <path-to-nepi>
23 # python examples/linux/hello_world.py -a <hostname> -u <username> -i <ssh-key>
24
25 from nepi.execution.ec import ExperimentController 
26
27 from optparse import OptionParser, SUPPRESS_HELP
28 import os
29
30 usage = ("usage: %prog -a <hostanme> -u <username> -i <ssh-key>")
31
32 parser = OptionParser(usage = usage)
33 parser.add_option("-a", "--hostname", dest="hostname", 
34         help="Remote host", type="str")
35 parser.add_option("-u", "--username", dest="username", 
36         help="Username to SSH to remote host", type="str")
37 parser.add_option("-i", "--ssh-key", dest="ssh_key", 
38         help="Path to private SSH key to be used for connection", 
39         type="str")
40 (options, args) = parser.parse_args()
41
42 hostname = options.hostname
43 username = options.username
44 ssh_key = options.ssh_key
45
46 ec = ExperimentController(exp_id = "src-up-exp")
47         
48 node = ec.register_resource("linux::Node")
49 ec.set(node, "hostname", hostname)
50 ec.set(node, "username", username)
51 ec.set(node, "identity", ssh_key)
52 ec.set(node, "cleanExperiment", True)
53 ec.set(node, "cleanProcesses", True)
54
55 path_to_sources = os.path.join(
56         os.path.dirname(os.path.realpath(__file__)),
57         "hello.c")
58
59 app = ec.register_resource("linux::Application")
60 ec.set(app, "sources", path_to_sources)
61 ec.set(app, "build", "gcc ${SRC}/hello.c -o ${BIN}/hello")
62 ec.set(app, "command", "${BIN}/hello")
63 ec.register_connection(node, app)
64
65 ec.deploy()
66
67 ec.wait_finished(app)
68
69 print ec.trace(app, "stdout")
70
71 ec.shutdown()
72