Fixing wrong license
[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 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 = "test_blacklist"
26 ec = ExperimentController(exp_id)
27
28 pl_user = os.environ.get("PL_USER")
29 pl_password =  os.environ.get("PL_PASS")
30 #username = os.environ.get("PL_SLICE")
31 username = 'inria_sfatest'
32
33 # nodes
34 node1 = ec.register_resource("planetlab::Node")
35 ec.set(node1, "username", username)
36 ec.set(node1, "pluser", pl_user)
37 ec.set(node1, "plpassword", pl_password)
38 ec.set(node1, "cleanExperiment", True)
39 ec.set(node1, "cleanProcesses", True)
40
41 node2 = ec.register_resource("planetlab::Node")
42 ec.set(node2, "username", username)
43 ec.set(node2, "pluser", pl_user)
44 ec.set(node2, "plpassword", pl_password)
45 ec.set(node2, "cleanExperiment", True)
46 ec.set(node2, "cleanProcesses", True)
47
48 node3 = ec.register_resource("planetlab::Node")
49 ec.set(node3, "username", username)
50 ec.set(node3, "pluser", pl_user)
51 ec.set(node3, "plpassword", pl_password)
52 ec.set(node3, "cleanExperiment", True)
53 ec.set(node3, "cleanProcesses", True)
54
55 # Set the global attribute 'persist_blacklist' 
56 # (that applies to all PlanetlabNodes) to persist the 
57 # use of the blacklist, meaning leaving out of the
58 # provisioning the nodes in that file, and adding the new blacklisted
59 # nodes to the file.
60 ec.set_global("planetlab::Node", "persist_blacklist", True)
61
62 # apps
63 app1 = ec.register_resource("linux::Application")
64 command = "ping -c5 google.com" 
65 ec.set(app1, "command", command)
66 ec.register_connection(app1, node1)
67
68 app2 = ec.register_resource("linux::Application")
69 command = "ping -c5 google.com" 
70 ec.set(app2, "command", command)
71 ec.register_connection(app2, node2)
72
73 app3 = ec.register_resource("linux::Application")
74 command = "ping -c5 google.com" 
75 ec.set(app3, "command", command)
76 ec.register_connection(app3, node3)
77
78 # Deploy
79 ec.deploy()
80
81 ec.wait_finished([app1, app2, app3])
82
83 ec.shutdown()
84
85 # The blacklisted nodes are saved in ~/.nepi/plblacklist.txt. 
86 # The next time the experiment is run these nodes will not be used.
87
88 # End