2 from nepi.execution.resource import ResourceManager, clsinit
3 from nepi.execution.attribute import Attribute, Flags
5 from nepi.resources.omf.omf_api import OMFAPIFactory
11 class OMFWifiInterface(ResourceManager):
13 .. class:: Class Args :
15 :param ec: The Experiment controller
16 :type ec: ExperimentController
17 :param guid: guid of the RM
19 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
24 This class is used only by the Experiment Controller through the Resource Factory
27 _rtype = "OMFWifiInterface"
28 _authorized_connections = ["OMFNode" , "OMFChannel"]
29 _waiters = ["OMFNode"]
31 #alias2name = dict({'w0':'wlan0', 'w1':'wlan1'})
34 def _register_attributes(cls):
35 """Register the attributes of an OMF interface
38 alias = Attribute("alias","Alias of the interface", default = "w0")
39 mode = Attribute("mode","Mode of the interface")
40 type = Attribute("type","Type of the interface")
41 essid = Attribute("essid","Essid of the interface")
42 ip = Attribute("ip","IP of the interface")
43 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential)
44 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential)
45 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential)
46 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential)
47 cls._register_attribute(alias)
48 cls._register_attribute(xmppSlice)
49 cls._register_attribute(xmppHost)
50 cls._register_attribute(xmppPort)
51 cls._register_attribute(xmppPassword)
52 cls._register_attribute(mode)
53 cls._register_attribute(type)
54 cls._register_attribute(essid)
55 cls._register_attribute(ip)
57 def __init__(self, ec, guid):
59 :param ec: The Experiment controller
60 :type ec: ExperimentController
61 :param guid: guid of the RM
63 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
67 super(OMFWifiInterface, self).__init__(ec, guid)
70 self._alias = self.get('alias')
72 self._logger = logging.getLogger("nepi.omf.omfIface ")
73 self._logger.setLevel(nepi.LOGLEVEL)
75 def _validate_connection(self, guid):
76 """ Check if the connection is available.
78 :param guid: Guid of the current RM
83 rm = self.ec.get_resource(guid)
84 if rm.rtype() in self._authorized_connections:
85 self._logger.debug("Connection between %s %s and %s %s accepted" %
86 (self.rtype(), self._guid, rm.rtype(), guid))
88 self._logger.debug("Connection between %s %s and %s %s refused" %
89 (self.rtype(), self._guid, rm.rtype(), guid))
92 def _get_nodes(self, conn_set):
93 """ Get the RM of the node to which the application is connected
95 :param conn_set: Connections of the current Guid
97 :rtype: ResourceManager
101 rm = self.ec.get_resource(elt)
102 if rm.rtype() == "OMFNode":
106 def deploy_action(self):
110 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'),
111 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
113 self._logger.debug(" " + self.rtype() + " ( Guid : " + str(self._guid) +") : " +
114 self.get('mode') + " : " + self.get('type') + " : " +
115 self.get('essid') + " : " + self.get('ip'))
117 if self.get('mode') and self.get('type') and self.get('essid') and self.get('ip'):
118 rm_node = self._get_nodes(self._connections)
119 for attrname in ["mode", "type", "essid", "ip"]:
120 attrval = self.get(attrname)
121 attrname = "net/%s/%s" % (self._alias, attrname)
122 #print "Send the configure message"
123 self._omf_api.configure(rm_node.get('hostname'), attrname, attrval)
125 super(OMFWifiInterface, self).deploy_action()
129 """Send Xmpp Messages Using OMF protocol to configure Interface
133 super(OMFWifiInterface, self).start()
136 """Send Xmpp Message Using OMF protocol to put down the interface
139 super(OMFWifiInterface, self).stop()
142 """Clean the RM at the end of the experiment
145 OMFAPIFactory.release_api(self.get('xmppSlice'),
146 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))