Adding attr critical = False for scalability example PL node
[nepi.git] / examples / planetlab / scalability.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
24 import os
25 import time
26
27 def create_node(ec, username, pl_user, pl_password, hostname=None, country=None,
28                 operatingSystem=None, minBandwidth=None, minCpu=None,
29                 critical=None):
30
31     node = ec.register_resource("PlanetlabNode")
32
33     if username:
34         ec.set(node, "username", username)
35     if pl_user:
36         ec.set(node, "pluser", pl_user)
37     if pl_password:
38         ec.set(node, "plpassword", pl_password)
39
40     if hostname:
41         ec.set(node, "hostname", hostname)
42     if country:
43         ec.set(node, "country", country)
44     if operatingSystem:
45         ec.set(node, "operatingSystem", operatingSystem)
46     if minBandwidth:
47         ec.set(node, "minBandwidth", minBandwidth)
48     if minCpu:
49         ec.set(node, "minCpu", minCpu)
50     if critical:
51         ec.set(node, "critical", critical)
52
53     ec.set(node, "cleanHome", True)
54     ec.set(node, "cleanProcesses", True)
55     
56     return node
57
58 exp_id = "scalability_exp"
59
60 # Create the entity Experiment Controller:
61 ec = ExperimentController(exp_id)
62
63 # Register the nodes resources:
64
65 # The username in this case is the slice name, the one to use for login in 
66 # via ssh into PlanetLab nodes. Replace with your own slice name.
67 username = os.environ.get("PL_SLICE")
68
69 # The pluser and plpassword are the ones used to login in the PlanetLab web 
70 # site. Replace with your own user and password account information.
71 pl_user = os.environ.get("PL_USER")
72 pl_password =  os.environ.get("PL_PASS")
73
74 # Choose the PlanetLab nodes for the experiment, in this example 5 nodes are
75 # used, and they are picked according to different criterias.
76
77 first_set_nodes = []
78 second_set_nodes = []
79 third_set_nodes = []
80
81 # First set of nodes will be defined by its hostname.
82 hostnames = ['planetlab2.utt.fr',
83 'planetlab-2.man.poznan.pl',
84 'planetlab-1.ing.unimo.it',
85 'gschembra3.diit.unict.it',
86 'planetlab2.ionio.gr',
87 'planetlab-1.imag.fr',
88 'node2pl.planet-lab.telecom-lille1.eu',
89 'planetlab1.xeno.cl.cam.ac.uk',
90 'planetlab3.hiit.fi',
91 'planetlab2.fri.uni-lj.si',
92 'planetlab1.informatik.uni-erlangen.de',
93 'node1pl.planet-lab.telecom-lille1.eu',
94 'planet2.servers.ua.pt',
95 'iraplab1.iralab.uni-karlsruhe.de',
96 'planetlab-node3.it-sudparis.eu',
97 'planet1.elte.hu',
98 'planet1.l3s.uni-hannover.de',
99 'planetlab1.fct.ualg.pt',
100 'host1.planetlab.informatik.tu-darmstadt.de',
101 'vicky.planetlab.ntua.gr',
102 'planetlab1.rutgers.edu']
103
104 for hostname in hostnames:
105     node = create_node(ec, username, pl_user, pl_password, hostname=hostname,
106             critical=False)
107     first_set_nodes.append(node)
108
109 # Second set of nodes will be U.S.A. nodes.
110 country = "United States"
111 for i in range(15):
112     node = create_node(ec, username, pl_user, pl_password, country=country,
113             critical=False)
114     second_set_nodes.append(node)
115
116 # Third set of nodes can be any node in Planetlab testbed.
117 for i in range(70):
118     node = create_node(ec, username, pl_user, pl_password, critical=False)
119     third_set_nodes.append(node)
120
121 # Register conditions
122
123 # The nodes that are completely identified by their hostnames have to be provisioned 
124 # before the rest of the nodes. This assures that no other resource will use the
125 # identified node even if the constraints matchs. 
126 # In this example the nodes from the first need to be provisioned before the ones in
127 # the second and third group. Using the same logic, is convenient that nodes from the
128 # second group are provisioned before nodes from the third group.
129
130 ec.register_condition(second_set_nodes, ResourceAction.DEPLOY, first_set_nodes, ResourceState.PROVISIONED)
131 ec.register_condition(third_set_nodes, ResourceAction.DEPLOY, second_set_nodes, ResourceState.PROVISIONED)
132     
133 # Deploy the experiment:
134 ec.deploy()
135
136 # Wait until all nodes are provisioned:
137 ec.wait_deployed(first_set_nodes)
138 ec.wait_deployed(second_set_nodes)
139 ec.wait_deployed(third_set_nodes)
140
141 # Do the experiment controller shutdown:
142 ec.shutdown()
143
144 # END