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
25 from nepi.resources.omf.omf_resource import ResourceGateway, OMFResource
26 from nepi.resources.omf.omf_api import OMFAPIFactory
32 class OMFNode(OMFResource):
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")
58 cls._register_attribute(hostname)
60 # XXX: We don't necessary need to have the credentials at the
61 # moment we create the RM
62 def __init__(self, ec, guid):
64 :param ec: The Experiment controller
65 :type ec: ExperimentController
66 :param guid: guid of the RM
70 super(OMFNode, self).__init__(ec, guid)
74 def valid_connection(self, guid):
75 """ Check if the connection with the guid in parameter is possible.
76 Only meaningful connections are allowed.
78 :param guid: Guid of the current RM
83 rm = self.ec.get_resource(guid)
84 if rm.rtype() in self._authorized_connections:
85 msg = "Connection between %s %s and %s %s accepted" % (
86 self.rtype(), self._guid, rm.rtype(), guid)
91 msg = "Connection between %s %s and %s %s refused" % (
92 self.rtype(), self._guid, rm.rtype(), guid)
98 """ Deploy the RM. It means : Send Xmpp Message Using OMF protocol
99 to enroll the node into the experiment.
100 It becomes DEPLOYED after sending messages to enroll the node
103 if not self._omf_api :
104 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'),
105 self.get('xmppHost'), self.get('xmppPort'),
106 self.get('xmppPassword'), exp_id = self.ec.exp_id)
108 if not self._omf_api :
109 msg = "Credentials are not initialzed. XMPP Connections impossible"
114 if not self.get('hostname') :
115 msg = "Hostname's value is not initialized"
121 self._omf_api.enroll_host(self.get('hostname'))
122 except AttributeError:
123 msg = "Credentials are not initialzed. XMPP Connections impossible"
126 #raise AttributeError, msg
128 super(OMFNode, self).deploy()
131 """ Discover the availables nodes
137 """ Provision some availables nodes
143 """Start the RM. It means nothing special for an interface for now
144 It becomes STARTED as soon as this method starts.
148 super(OMFNode, self).start()
151 """Stop the RM. It means nothing special for an interface for now
152 It becomes STOPPED as soon as this method stops
155 super(OMFNode, self).stop()
158 """Clean the RM at the end of the experiment
162 self._omf_api.release(self.get('hostname'))
164 OMFAPIFactory.release_api(self.get('xmppSlice'),
165 self.get('xmppHost'), self.get('xmppPort'),
166 self.get('xmppPassword'), exp_id = self.ec.exp_id)
168 super(OMFNode, self).release()