68b01c6c802f31bdfb8b8f8e0f0139f3966f02b0
[nepi.git] / examples / planetlab / testing / blacklist.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 as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
20
21 from nepi.execution.ec import ExperimentController
22 from nepi.execution.resource import ResourceAction, ResourceState
23 import os
24
25 # Create the EC
26 exp_id = "test_blacklist"
27 ec = ExperimentController(exp_id)
28
29 pl_user = os.environ.get("PL_USER")
30 pl_password =  os.environ.get("PL_PASS")
31 #username = os.environ.get("PL_SLICE")
32 username = 'inria_sfatest'
33
34 # nodes
35 node1 = ec.register_resource("planetlab::Node")
36 ec.set(node1, "username", username)
37 ec.set(node1, "pluser", pl_user)
38 ec.set(node1, "plpassword", pl_password)
39 ec.set(node1, "cleanExperiment", True)
40 ec.set(node1, "cleanProcesses", True)
41
42 node2 = ec.register_resource("planetlab::Node")
43 ec.set(node2, "username", username)
44 ec.set(node2, "pluser", pl_user)
45 ec.set(node2, "plpassword", pl_password)
46 ec.set(node2, "cleanExperiment", True)
47 ec.set(node2, "cleanProcesses", True)
48
49 node3 = ec.register_resource("planetlab::Node")
50 ec.set(node3, "username", username)
51 ec.set(node3, "pluser", pl_user)
52 ec.set(node3, "plpassword", pl_password)
53 ec.set(node3, "cleanExperiment", True)
54 ec.set(node3, "cleanProcesses", True)
55
56 # Set the global attribute 'persist_blacklist' 
57 # (that applies to all PlanetlabNodes) to persist the 
58 # use of the blacklist, meaning leaving out of the
59 # provisioning the nodes in that file, and adding the new blacklisted
60 # nodes to the file.
61 ec.set_global("planetlab::Node", "persist_blacklist", True)
62
63 # apps
64 app1 = ec.register_resource("linux::Application")
65 command = "ping -c5 google.com" 
66 ec.set(app1, "command", command)
67 ec.register_connection(app1, node1)
68
69 app2 = ec.register_resource("linux::Application")
70 command = "ping -c5 google.com" 
71 ec.set(app2, "command", command)
72 ec.register_connection(app2, node2)
73
74 app3 = ec.register_resource("linux::Application")
75 command = "ping -c5 google.com" 
76 ec.set(app3, "command", command)
77 ec.register_connection(app3, node3)
78
79 # Deploy
80 ec.deploy()
81
82 ec.wait_finished([app1, app2, app3])
83
84 ec.shutdown()
85
86 # The blacklisted nodes are saved in ~/.nepi/plblacklist.txt. 
87 # The next time the experiment is run these nodes will not be used.
88
89 # End