2 from neco.execution.resource import Resource, clsinit
3 from neco.execution.attribute import Attribute
5 from neco.resources.omf.omf_api import OMFAPIFactory
11 class OMFWifiInterface(Resource):
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"]
30 #alias2name = dict({'w0':'wlan0', 'w1':'wlan1'})
33 def _register_attributes(cls):
34 """Register the attributes of an OMF interface
36 alias = Attribute("alias","Alias of the interface", default_value = "w0")
37 mode = Attribute("mode","Mode of the interface")
38 type = Attribute("type","Type of the interface")
39 essid = Attribute("essid","Essid of the interface")
40 ip = Attribute("ip","IP of the interface")
41 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = "0x02")
42 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = "0x02")
43 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = "0x02")
44 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = "0x02")
45 cls._register_attribute(alias)
46 cls._register_attribute(xmppSlice)
47 cls._register_attribute(xmppHost)
48 cls._register_attribute(xmppPort)
49 cls._register_attribute(xmppPassword)
50 cls._register_attribute(mode)
51 cls._register_attribute(type)
52 cls._register_attribute(essid)
53 cls._register_attribute(ip)
55 def __init__(self, ec, guid, creds):
57 :param ec: The Experiment controller
58 :type ec: ExperimentController
59 :param guid: guid of the RM
61 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
65 super(OMFWifiInterface, self).__init__(ec, guid)
66 self.set('xmppSlice', creds['xmppSlice'])
67 self.set('xmppHost', creds['xmppHost'])
68 self.set('xmppPort', creds['xmppPort'])
69 self.set('xmppPassword', creds['xmppPassword'])
71 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
72 self._alias = self.get('alias')
74 self._logger = logging.getLogger("neco.omf.omfIface ")
75 self._logger.setLevel(neco.LOGLEVEL)
77 def _validate_connection(self, guid):
78 """Check if the connection is available.
80 :param guid: Guid of the current RM
85 rm = self.ec.resource(guid)
86 if rm.rtype() in self._authorized_connections:
87 self._logger.debug("Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid))
89 self._logger.debug("Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid))
92 def _get_nodes(self, conn_set):
94 Get the RM of the node to which the application is connected
96 :param conn_set: Connections of the current Guid
98 :rtype: ResourceManager
101 rm = self.ec.resource(elt)
102 if rm.rtype() == "OMFNode":
108 """Send Xmpp Messages Using OMF protocol to configure Interface
111 self._logger.debug(self.rtype() + " ( Guid : " + str(self._guid) +") : " + self.get('mode') + " : " + self.get('type') + " : " + self.get('essid') + " : " + self.get('ip'))
113 if self.get('mode') and self.get('type') and self.get('essid') and self.get('ip'):
114 rm_node = self._get_nodes(self._connections)
115 for attrname in ["mode", "type", "essid", "ip"]:
116 attrval = self.get(attrname)
117 attrname = "net/%s/%s" % (self._alias, attrname)
118 #print "Send the configure message"
119 self._omf_api.configure(rm_node.get('hostname'), attrname, attrval)
122 """Send Xmpp Message Using OMF protocol to put down the interface
125 self._omf_api.disconnect()