Adding CCN RMs for Linux backend
[nepi.git] / examples / linux / ccn / vlc_2_hosts_ccndrms.py
1 #!/usr/bin/env python
2
3 #
4 #    NEPI, a framework to manage network experiments
5 #    Copyright (C) 2013 INRIA
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation, either version 3 of the License, or
10 #    (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
21
22 from nepi.execution.ec import ExperimentController, ECState 
23 from nepi.execution.resource import ResourceState, ResourceAction, \
24         populate_factory
25 from nepi.resources.linux.node import OSType
26
27 from optparse import OptionParser, SUPPRESS_HELP
28
29 import os
30 import time
31
32 def add_node(ec, host, user, ssh_key = None):
33     node = ec.register_resource("LinuxNode")
34     ec.set(node, "hostname", host)
35     ec.set(node, "username", user)
36     ec.set(node, "identity", ssh_key)
37     ec.set(node, "cleanHome", True)
38     ec.set(node, "cleanProcesses", True)
39     return node
40
41 def add_ccnd(ec, node):
42     ccnd = ec.register_resource("LinuxCCND")
43     ec.register_connection(ccnd, node)
44     return ccnd
45
46 def add_ccnr(ec, ccnd, node):
47     ccnr = ec.register_resource("LinuxCCNR")
48     ec.register_connection(ccnr, node)
49     ec.register_connection(ccnr, ccnd)
50
51     return ccnr
52
53 if __name__ == '__main__':
54     # Search for available RMs
55     populate_factory()
56     
57     ec = ExperimentController(exp_id = "olahh")
58     
59     # hosts
60     host1 = 'planetlab2.u-strasbg.fr'
61     host2 = 'roseval.pl.sophia.inria.fr'
62
63     # users
64     user1 = "inria_alina"
65     user2 = "alina"
66
67     # Register a ResourceManagers (RMs)
68
69     node1 = add_node(ec, host1, user1)
70     ccnd1 = add_ccnd(ec, node1)
71     ccnr1 = add_ccnr(ec, ccnd1, node1)
72
73     node2 = add_node(ec, host2, user2)
74     ccnd2 = add_ccnd(ec, node2)
75     ccnr2 = add_ccnr(ec, ccnd2, node2)
76  
77     # Deploy all ResourceManagers
78     ec.deploy()
79
80     ec.wait_started([ccnd1, ccnr1, ccnd2, ccnr2])
81
82     # Shutdown the experiment controller
83     ec.shutdown()
84