Fixing wrong license
[nepi.git] / examples / planetlab / testing / ping_sfa.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: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
19
20 from nepi.execution.ec import ExperimentController
21 from nepi.execution.resource import ResourceAction, ResourceState
22 import os
23
24 # Create the EC
25 exp_id = "sfa_test"
26 ec = ExperimentController(exp_id)
27
28 #username = os.environ.get('SFA_SLICE')
29 username = 'inria_lguevgeo'
30 sfauser = os.environ.get('SFA_USER')
31 sfaPrivateKey = os.environ.get('SFA_PK')
32
33 # server
34 node1 = ec.register_resource("planetlab::sfa::Node")
35 ec.set(node1, "hostname", "planetlab3.xeno.cl.cam.ac.uk")
36 ec.set(node1, "username", username)
37 ec.set(node1, "sfauser", sfauser)
38 ec.set(node1, "sfaPrivateKey", sfaPrivateKey)
39 ec.set(node1, "cleanExperiment", True)
40 ec.set(node1, "cleanProcesses", True)
41
42 node2 = ec.register_resource("planetlab::sfa::Node")
43 ec.set(node2, "username", username)
44 ec.set(node2, "sfauser", sfauser)
45 ec.set(node2, "sfaPrivateKey", sfaPrivateKey)
46 ec.set(node2, "cleanExperiment", True)
47 ec.set(node2, "cleanProcesses", True)
48
49 node3 = ec.register_resource("planetlab::sfa::Node")
50 ec.set(node3, "username", username)
51 ec.set(node3, "sfauser", sfauser)
52 ec.set(node3, "sfaPrivateKey", sfaPrivateKey)
53
54 app1 = ec.register_resource("linux::Application")
55 command = "ping -c5 google.com" 
56 ec.set(app1, "command", command)
57 ec.register_connection(app1, node1)
58
59 app2 = ec.register_resource("linux::Application")
60 command = "ping -c5 google.com" 
61 ec.set(app2, "command", command)
62 ec.register_connection(app2, node2)
63
64 app3 = ec.register_resource("linux::Application")
65 command = "ping -c5 google.com"
66 ec.set(app3, "command", command)
67 ec.register_connection(app3, node3)
68
69 ec.register_condition(node2, ResourceAction.DEPLOY, node1, ResourceState.PROVISIONED)
70 ec.register_condition(node3, ResourceAction.DEPLOY, node1, ResourceState.PROVISIONED)
71
72 # Deploy
73 ec.deploy()
74
75 ec.wait_finished([app1, app2, app3])
76
77 ec.shutdown()
78
79 # End