8a95124b645e2313989f5e26f211989339b4dc73
[nepi.git] / doc / templates / template_rm.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2013 INRIA
4 #
5 #    This program is free software: you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License as published by
7 #    the Free Software Foundation, either version 3 of the License, or
8 #    (at your option) any later version.
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 # Authors: Alina Quereilhac <alina.quereilhac@inria.fr>
19 #          Julien Tribino <julien.tribino@inria.fr>
20
21
22
23 from nepi.execution.attribute import Attribute, Flags, Types
24 from nepi.execution.resource import ResourceManager, clsinit_copy, \
25         ResourceState, reschedule_delay
26
27 #import time
28 #import threading
29
30 #clsinit_copy is used to copy the attirbute from parent class
31 @clsinit_copy
32 class RMName(ResourceManager):
33         
34     _rtype = "RMName" # Name that will be used in the Experiment Description Script 
35     _help = "Help that describe the RM"
36     _backend_type = "backend" # Name of the platform this RM is attached. 
37     _authorized_connections = ["RMName1" , "RMName2"] # list of valid connection for this RM
38
39
40     @classmethod
41     def _register_attributes(cls):
42     '''
43         This method is used to register all the attribute of this RM. Check the
44         file src/execution/attribute.py to see all the fields of this class
45     '''
46
47         attribute1 = Attribute("nameOfAttribute1", "Description of the Attribute 1",
48                 flags = Flags.Design)
49
50         attribute2 = Attribute("nameOfAttribute2", "Description of the Attribute 2",
51                 flags = Flags.Design)
52
53         cls._register_attribute(attribute1)
54         cls._register_attribute(attribute2)
55
56     def __init__(self, ec, guid):
57     '''
58         In the init, we usually intialize the variable of the RM that are not attribute
59     '''
60
61         super(RMName, self).__init__(ec, guid)
62
63         self.var1 = None
64
65     
66     def log_message(self, msg):
67     '''
68         In some particular cases, it is required to redefined the log of the RM.
69         The default log require the name of the node, but sometimes, 
70         it does not mean something.
71     '''
72         return " guid %d - host %s - %s " % (self.guid, 
73                 self.get("hostname"), msg)
74
75
76     def valid_connection(self, guid):
77     '''
78         Check if the connection is valide or not, depending on the list povided in the parameter
79         _authorized_connection described above
80     '''
81         return True
82
83     # This one is not mandatory
84     def do_discover(self):
85     '''
86         Do anything required to discover the resource.The meaning of discover
87         is different for each RM 
88     '''
89         super(RMName, self).do_discover()
90
91     # This one is not mandatory
92     def do_provision(self):
93     '''
94         Do anything required to provision the resource.The meaning of provision
95         is different for each RM 
96     '''
97         super(RMName, self).do_provision()
98
99     def do_deploy(self):
100     '''
101         Do anything required to deploy the resource.The meaning of deploy 
102         is different for each RM 
103     '''
104         super(RMName, self).do_deploy()
105
106
107     def do_start(self):
108     '''
109         Do anything required to start the resource.The meaning of start 
110         is different for each RM 
111     '''
112         super(RMName, self).do_release()
113
114
115     def do_stop(self):
116     '''
117         Do anything required to stop the resource.The meaning of stop 
118         is different for each RM 
119     '''
120         super(RMName, self).do_release()
121
122     def do_release(self):
123     '''
124         Do anything required to release the resource.The meaning of release 
125         is different for each RM 
126     '''
127         super(RMName, self).do_release()
128
129