2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2013 INRIA
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.
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.
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/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 # Julien Tribino <julien.tribino@inria.fr>
22 from nepi.execution.resource import ResourceManager, clsinit, ResourceState, \
24 from nepi.execution.attribute import Attribute, Flags
26 from nepi.resources.omf.omf_api import OMFAPIFactory
32 class OMFNode(ResourceManager):
34 .. class:: Class Args :
36 :param ec: The Experiment controller
37 :type ec: ExperimentController
38 :param guid: guid of the RM
40 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
45 This class is used only by the Experiment Controller through the Resource Factory
49 _authorized_connections = ["OMFApplication" , "OMFWifiInterface"]
52 def _register_attributes(cls):
53 """Register the attributes of an OMF Node
56 hostname = Attribute("hostname", "Hostname of the machine")
57 cpu = Attribute("cpu", "CPU of the node")
58 ram = Attribute("ram", "RAM of the node")
59 xmppSlice = Attribute("xmppSlice","Name of the slice",
60 flags = Flags.Credential)
61 xmppHost = Attribute("xmppHost", "Xmpp Server",
62 flags = Flags.Credential)
63 xmppPort = Attribute("xmppPort", "Xmpp Port",
64 flags = Flags.Credential)
65 xmppPassword = Attribute("xmppPassword", "Xmpp Port",
66 flags = Flags.Credential)
68 host = Attribute("host", "Hostname of the machine",
70 gateway = Attribute("gateway", "Gateway",
72 granularity = Attribute("granularity", "Granularity of the reservation time",
74 hardware_type = Attribute("hardware_type", "Hardware type of the machine",
77 cls._register_attribute(hostname)
78 cls._register_attribute(ram)
79 cls._register_attribute(cpu)
80 cls._register_attribute(xmppSlice)
81 cls._register_attribute(xmppHost)
82 cls._register_attribute(xmppPort)
83 cls._register_attribute(xmppPassword)
85 cls._register_attribute(host)
86 cls._register_attribute(gateway)
87 cls._register_attribute(granularity)
88 cls._register_attribute(hardware_type)
90 # XXX: We don't necessary need to have the credentials at the
91 # moment we create the RM
92 def __init__(self, ec, guid):
94 :param ec: The Experiment controller
95 :type ec: ExperimentController
96 :param guid: guid of the RM
100 super(OMFNode, self).__init__(ec, guid)
106 if self.ec.exp_id.startswith('exp-'):
108 return self.ec.exp_id
110 def valid_connection(self, guid):
111 """Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed.
113 :param guid: Guid of the current RM
118 rm = self.ec.get_resource(guid)
119 if rm.rtype() in self._authorized_connections:
120 msg = "Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid)
123 msg = "Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid)
128 """Deploy the RM. It means : Send Xmpp Message Using OMF protocol to enroll the node into the experiment
129 It becomes DEPLOYED after sending messages to enroll the node
132 if not self._omf_api :
133 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'),
134 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
136 if not self._omf_api :
137 self._state = ResourceState.FAILED
138 msg = "Credentials are not initialzed. XMPP Connections impossible"
142 if not self.get('hostname') :
143 self._state = ResourceState.FAILED
144 msg = "Hostname's value is not initialized"
149 self._omf_api.enroll_host(self.get('hostname'))
150 except AttributeError:
151 self._state = ResourceState.FAILED
152 msg = "Credentials are not initialzed. XMPP Connections impossible"
154 #raise AttributeError, msg
156 super(OMFNode, self).deploy()
159 """ Discover the availables nodes
165 """ Provision some availables nodes
171 """Start the RM. It means nothing special for an interface for now
172 It becomes STARTED as soon as this method starts.
176 super(OMFNode, self).start()
179 """Stop the RM. It means nothing special for an interface for now
180 It becomes STOPPED as soon as this method stops
183 super(OMFNode, self).stop()
186 """Clean the RM at the end of the experiment
190 self._omf_api.release(self.get('hostname'))
191 OMFAPIFactory.release_api(self.get('xmppSlice'),
192 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
194 super(OMFNode, self).release()